option to another select list after checking against a lookup array .
My problem now is that the script only works properly on the first select
list in the list. It "appears" to work with the others, however, it
actually contains the data from the first list.
The functions are called by the onchange handler for the associated
select list, like so:
HANDLER:
Code: Select all
<select name="selIngredientї<?php echo $i ?>]" onChange="JavaScript:
addToSelect(<?php echo $arrName ?>, <?php echo $i ?>);" size="1" id="<?
php echo $i ?>">Code: Select all
function addToSelect(arr, c)
{
var oOption;
var len = document.formsї1].elementsї0].options.length;
var target = parseInt(document.formsї1].elementsї0].optionsїc].index);
alert(target);
for(var t = 0; t < len; t++)
{
if(document.formsї1].elementsї0].optionsїt].selected ==
true )
{
var text = document.formsї1].elementsї0].optionsїt].value;
text = text.split(":");
for(var j = 0; j < arr.length; ++j)
{
var lookFor = arrїj].split(":");
if( textї1] == lookForї0] )
{
alert(lookForї0] + ':' + lookForї1]);
alert('Found conversion ' + lookForї1] + ' for
ingredient ' + lookForї0]);
oOption = new Option(lookForї1], lookForї1]);
//alert(oOption);
document.formsї1].elementsї(target+2)].add
(oOption);
alert(oOption.text + ' is the text\n' +
oOption.value + ' is the value.');
}
}
}
}
}