OK...here's my latest incarnation of my script. Essentially this adds an
option to another select list after checking against a lookup array .
My problem now is that the script only works peoperly 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:
FUNCTION CODE
option to another select list after checking against a lookup array .
My problem now is that the script only works peoperly 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 name="selIngredient[<?php echo $i ?>]" onChange="JavaScript:
addToSelect(<?php echo $arrName ?>, <?php echo $i ?>);" size="1" id="<?
php echo $i ?>">
Code:
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 )
{
//alert('Option index is: ' + document.forms[1].elements
[0].options[t].index );
var text = document.forms[1].elements[0].options[t].value;
text = text.split(":");
//alert(text[1]);
//alert('Option value is ' + document.forms[1].elements
[0].options[t].value);
for(var j = 0; j < arr.length; ++j)
{
var lookFor = arr[j].split(":");
//alert('Looking for ' + lookFor[0]);
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.');
}
}
}
}
}