PDA

View Full Version : Need some help on a loop



gszauer
01-10-2007, 08:33 PM
<script language="Javascript" type="text/javascript">
<!-- Hide from older browsers
a0 = new array(
new Array("title", "url"),
new Array("title2", "url"),
new Array("title3", "url")
)
function changeMenu (arrayName){
selected = document.mainDcument.categories.options[document.mainDcument.categories.selectedIndex].value
if (selected != ""){
selectedValue = parseInt(selected)
document.mainDcument.playlist.options.length = 0
for (i=0; i<=arrayName.length ; i++){
document.mainDcument.playlist.options[i] = new Option(arrayName[i][0])
// arrayName[i][0]
//document.mainDcument.playlist.options[i].value = i
}
}
}
// end hiding script -->
</script>
If i replace

document.mainDcument.playlist.options[i] = new Option(arrayName[i][0])
with

document.mainDcument.playlist.options[i] = new Option("Dummy")
The script works just fine, but otherwise it refuses to populate my other list...
Can anyone please help out?
I appriciate your time
Thanks
~Gabor

Kenny
01-11-2007, 01:05 AM
I would look into this...

a0 = new array();
a0[0]= new Array("title", "url");
a0[1]= new Array("title2", "url");
a0[2]= new Array("title3", "url");

gszauer
01-11-2007, 01:16 AM
tryed that it didn't work.
Also, to my knowlege in Javascript you do not need to end your lines with ;


If it helps, my full code is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="Javascript" type="text/javascript">
<!-- Hide from older browsers
a0 = new array(
new Array("title", "url"),
new Array("title2", "url"),
new Array("title3", "url")
)
function changeMenu (arrayName){
selected = document.mainDcument.categories.options[document.mainDcument.categories.selectedIndex].value
if (selected != ""){
selectedValue = parseInt(selected)
document.mainDcument.playlist.options.length = 0
for (i=0; i<=arrayName.length ; i++){
document.mainDcument.playlist.options[i] = new Option(arrayName[i][0])
// arrayName[i][0]
//document.mainDcument.playlist.options[i].value = i
}
}
}
// end hiding script -->
</script>
</head>
<body>
<form name="mainDcument" action="http://">
<select name="categories" size="5" id="categories" onchange="changeMenu ('a0')">
<option value="0">populate</option>
<option value="1">populate</option>
<option value="2">populate</option>
</select>
<select name="playlist" size="5" id="playlist" onChange="changeMenu ()">
<option value="0">UnPopulated</option>
</select>
</form>
</body>
</html>