Page 1 of 1

Mixing PHP and JS, getting mixed results..

Posted: Thu Sep 05, 2002 12:43 pm
by phpPete
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 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&#1111;<?php echo $i ?>]" onChange="JavaScript: 
addToSelect(<?php echo $arrName ?>, <?php echo $i  ?>);" size="1" id="<?
php echo $i ?>">
FUNCTION CODE

Code: Select all

function addToSelect(arr, c)
&#123;
    var oOption;
    var len = document.forms&#1111;1].elements&#1111;0].options.length;
    var target = parseInt(document.forms&#1111;1].elements&#1111;0].options&#1111;c].index);
    alert(target);
 
    for(var t = 0; t < len;  t++)
    &#123;
       
        if(document.forms&#1111;1].elements&#1111;0].options&#1111;t].selected == 
true )        
        &#123;            
            
            var text = document.forms&#1111;1].elements&#1111;0].options&#1111;t].value;
            text = text.split(":");
           
            
            
             for(var j = 0; j < arr.length; ++j)
                &#123;
                    var lookFor = arr&#1111;j].split(":");
                 if( text&#1111;1] == lookFor&#1111;0] )
                       &#123;
                       alert(lookFor&#1111;0] + ':' + lookFor&#1111;1]);
                       alert('Found conversion  '  + lookFor&#1111;1] + '  for 
ingredient ' + lookFor&#1111;0]);
                          oOption = new Option(lookFor&#1111;1], lookFor&#1111;1]); 
                          //alert(oOption);               
                          document.forms&#1111;1].elements&#1111;(target+2)].add
(oOption);
                          alert(oOption.text + ' is the text\n' + 
oOption.value + ' is the value.');
                      &#125;
                 &#125;    
             &#125; 
        &#125; 
    &#125;