View Full Version : Passing parameter

10-02-2008, 01:35 PM
I am developing in perl + html…
I have three combo boxes and a button that allow the dynamic addition of another three dropdowns(as many times as I wish).

The HTML code is as follows:

print "<td><select name=plateforme0 style=\"COLOR:#666666;font-weight: bold;width:200\" onChange=\"reload(this.form.plateforme0.options[this.form.plateforme0.selectedIndex].text)\"><option></option>";
foreach (@plateforme_f) { print "<option>$_->[0]</option>";}
print "</select></td></tr>\n";
#foreach (@plateforme) { print "<option>$_->[0] - $_->[2]</option>";}
print "<tr><td width=230>Carte</td>";
print "<td><select name=carte0 style=\"COLOR:#666666;font-weight: bold;width:200\" onChange=\"reload_carte(this.form.carte0.options[this.form.carte0.selectedIndex].text)\"><option></option>";
print "</select></td></tr>\n";

print "<tr><td>Version</td>";
print "<td><select name=version0 style=\"COLOR:#666666;font-weight: bold;width:200\" ><option></option>";
print "</select>";

print "<td><input type=hidden id=\"theValue\" value=\"0\" /><a href=\"javascript:;\" onclick=\"addElement();\">add</a></td><br/>";

The part => onChange=\"reload(this.form.plateforme0.options[this.form.plateforme0.selectedIndex].text)\" will call a javascript function that will update the options in the second combo box.

JAVASCRIPT code to add 3 dynamic combo boxes:

print "function addElement()";
print "{";

my @plateforme_f = $_BD->select("SELECT DISTINCT plateforme FROM kagoor_versions ORDER BY plateforme ASC");
print "var html = document.getElementById('myDiv').innerHTML;";
print "document.getElementById('myDiv').innerHTML=html+'<table><td width=230>Plateforme</td><td><select name=plateforme'+x+' style=\"COLOR:#666666;font-weight: bold;width:200\" onChange=\"reload(this.form.plateforme'+x+'.options[this.form.plateforme'+x+'.selectedIndex].text)\"><option></option>";
foreach (@plateforme_f)
print "<option>$_->[0]</option>";
print "</select></td>";
print "<td width=45></td><tr><td width=230>Carte</td><td><select name=carte'+x+' style=\"COLOR:#666666;font-weight: bold;width:200\" onChange=\"reload_carte()\"><option></option>";
print "</select></td>";
print "<tr><td>Version</td>";
print "<td><select name=version style=\"COLOR:#666666;font-weight: bold;width:200\" ><option></option>";
print "</select></tr></table>';";
print "x++;";
print "}";


print "function reload(y)";
print "{";

print "var val=y;\n";
print "alert(val);\n";
my @q2 = $_BD->select("select DISTINCT plateforme FROM kagoor_versions");

foreach (@q2)
print "if(val == '$_->[0]'){";

my @q3 = $_BD->select("select carte_SIG_H323 from kagoor_versions where plateforme='$_->[0]' AND carte_SIG_H323<>''");
print "removeAllOptions(document.formu.carte);";

foreach (@q3)
print "addOption(document.formu.carte,'$_->[0]', '$_->[0]');";
print "}";

print "}";

print "function removeAllOptions(selectbox)
var i;

function addOption(selectbox, value, text )
var optn = document.createElement(\"OPTION\");
optn.text = text;
optn.value = value;

The first 3 original combo works fine.

The problem is when I add three additional combo and when I select an option for the first combo, the second combo is not updated. I am unable to pass the right combo i.e carte1 (when x=1) P in the function removeAllOptions(document.formu.carte).:confused:
Can anybody please help.