i have a javascript that updates menu 2 when you pick a country from menu 1. it works fine once the page is loaded but when the page first loads up menu 2 is blank if menu 1 has an option in menu 1 selected, i want menu 2 to preload the values in menu 2. i dont want to use the onload in the <body> tag. is there away to load menu 2 with the options when the page first loads?
heres my code. so if UK is selected when the page loads, as in the code i want 'Mortlake' to display, so i do not need to pick USA and then UK again to display the options in UK.
<script>
var browser_type=navigator.appName
var co4 = new Array(
"Mortlake")
var co3 = new Array(
"1","Maplewood")
function updateList(theForm, catName, subjListLength){
for (var i=subjListLength + 1 ; i > 0 ; i-- )
{
theForm.header_lid.options = null
}
if( catName == ""){
var option0 = new Option("Territory", "")
}
else{
eval('var option0 = new Option("Territory", "")')
}
NSL=0
if (catName != "None") {
eval("var NewSource = " + "co"+ catName)
NSL = NewSource.length
for(var L = 0; L < NSL + 1; L++) {
eval("var option" + [L + 1] + " = new Option(" + '"' + NewSource[L] + '", "' + NewSource[L] + '")')
}
}
for (var i=0; i < NSL + 1; i++) {
eval("theForm.header_lid.options=option" + i)
if (i==0) {
theForm.header_lid.options.selected=true
}
}
if (browser_type=="Netscape")
{ history.go(0) }
}
</script>
this is the form
<form action="home.php" method="post">
country:
<select name="header_cid" class="NavDD" onChange="updateList(this.form, this.options[selectedIndex].value, this.form.header_lid.length)">
<option value="">Country</option>
<option value="4" selected>United Kingdom</option>
<option value="3" >USA</option>
</select>
territory:
<select name="header_lid" class="NavDD" id="header_lid">
<option value="" selected>Territory</option>
</select>
</form>
javascript help on array preload
Moderator: General Moderators
-
tylerdurden
- Forum Commoner
- Posts: 66
- Joined: Mon Jul 28, 2003 11:52 am
- Location: Austria
You could simply call your function at the end of the script, after the function definition. No need to use onLoad.
Are you sure the script works apart from this problem? I didn't get it to run in Mozilla or Safari.
Check out http://www.titleofsite.com/foo.html for a similar script I prepared.
Are you sure the script works apart from this problem? I didn't get it to run in Mozilla or Safari.
Check out http://www.titleofsite.com/foo.html for a similar script I prepared.
tylerdurden i been using the script you gave me. i'm having problems.
i push the ids dynamically from a database, it is not neccessary that my id values in the first select box or second, third select box are going to be uniform i.e. 1,2,3 they could be 3,2,6,77 in select box 1 and 3,5,99,44 in select box 2. you use uniform values to loop your array. how can i get around this?
i push the ids dynamically from a database, it is not neccessary that my id values in the first select box or second, third select box are going to be uniform i.e. 1,2,3 they could be 3,2,6,77 in select box 1 and 3,5,99,44 in select box 2. you use uniform values to loop your array. how can i get around this?
-
tylerdurden
- Forum Commoner
- Posts: 66
- Joined: Mon Jul 28, 2003 11:52 am
- Location: Austria
I have a strange menu system. depending on which user level logs in the menus can range from one select box to 3 select boxs. so i need to be able to put a if statement around how many select boxes to display.
i have one select box with countries listed, second with territories and the third with schools.
if a principal logs in the only territory and school display.
if a country level logs in then country territory and school display.
Also i noticed that the second or third select box does not accept 'selected' values unless they exists as a key in the first select box. How can i make the selected value in the second and third select box?
i would appreciate if you could clean it up and send me a copy. thank you for all your help.
i have one select box with countries listed, second with territories and the third with schools.
if a principal logs in the only territory and school display.
if a country level logs in then country territory and school display.
Also i noticed that the second or third select box does not accept 'selected' values unless they exists as a key in the first select box. How can i make the selected value in the second and third select box?
i would appreciate if you could clean it up and send me a copy. thank you for all your help.
-
tylerdurden
- Forum Commoner
- Posts: 66
- Joined: Mon Jul 28, 2003 11:52 am
- Location: Austria
Here you go:
http://www.titleofsite.com/selects/foo_new.html
with three selects.
http://www.titleofsite.com/selects/foo_new2.html
with two selects.
http://www.titleofsite.com/selects/foo_new4.html
with four selects.
Could be prettier I think, but it's cleaned up and it works. (Haven't tested it in IE Windows, could you give it a try?)
http://www.titleofsite.com/selects/foo_new.html
with three selects.
http://www.titleofsite.com/selects/foo_new2.html
with two selects.
http://www.titleofsite.com/selects/foo_new4.html
with four selects.
Could be prettier I think, but it's cleaned up and it works. (Haven't tested it in IE Windows, could you give it a try?)