Forum Moderators: open
<SELECT value="oldroom" onChange="makemenu(this.option(selectedIndex).value)">
function makemenu(elementid){
HTML
foreach (@building){
chomp $_;
print "\n\t\t\tvar $_ = new Array()\n";
$i=0;
$query9=$dbh->prepare("SELECT room FROM roomid WHERE building=\"$_\";");
$query9->execute;
while(@row9=$query9->fetchrow_array()){
foreach $room(@row9){
chomp $_;
print "\t\t\t$_\[$i]\=\"$room\";\n";
$i++;
}
}
}
print <<HTML;
//var j=1;
for(var i=0;i<elementid.length;i++){
alert(elementid[i]);
//document.forms[0].oldroom.options[j] = new Option(elementid[i],elementid[i]);
//j++;
}
}
Don't know if you have named elements in the JS array... But, you cannot access the size (length) of a variable containing named elements without specifying the number of elements it has when creating it.
<script type="text/javascript">
foo = new Array();
foo['bar'] = "test";
foo['baz'] = "widget";
bar = new Array(2);
bar['bar'] = "test";
bar['baz'] = "widget";
baz = new Array();
baz[0] = "test";
baz[2] = "widget";
widget = new Array(1);
widget[0] = "test";
widget[199] = "widget";
blah = new Array(50);
blah[0] = "test";
blah[2] = "widget";
alert("'foo' has " + foo.length + " elements\n'bar' has " + bar.length + " elements\n'baz' has " + baz.length + " elements\n'widget' has " + widget.length + " elements\n'blah' has " + blah.length + " elements");
</script>
function makemenu(elementid){
rooms=new Array()
HTML
foreach (@building){
$value="";
$query9=$dbh->prepare("SELECT room FROM roomid WHERE building=\"$_\";");
$query9->execute;
while(@row9=$query9->fetchrow_array()){
foreach $room(@row9){
push(@tmp, $room);
$temp="\"$room\"";
$value=$value."$temp,"
}
}
chop $value;
print "\t\t\trooms[\"$_\"]=new Array($value);\n";
undef @tmp;
}
print <<HTML;
var j=1;
var i;
for(i=0;i<rooms[elementid].length;i++){
document.forms[0].oldroom.options[j] = new Option(rooms[elementid][i],rooms[elementid][i],false,false);
j++;
}
}