Javascript within a form
I'm trying to have the select box change when I pick a specific array. Why won't this work.
// Continental US Options
contus1List = new Array(
contus2List = new Array(
contus3List = new Array(6)
// Weather and Temperature Aloft
contus1List[0] = "Flight Level 5,000"
contus1List[1] = "Flight Level 10,000"
contus1List[2] = "Flight Level 18,000"
contus1List[3] = "Flight Level 24,000"
contus1List[4] = "Flight Level 30,000"
contus1List[5] = "Flight Level 34,000"
contus1List[6] = "Flight Level 39,000"
contus1List[7] = "Flight Level 45,000"
// Upper Air Analysis
contus2List[0] = "Flight Level 5,000"
contus2List[1] = "Flight Level 10,000"
contus2List[2] = "Flight Level 18,000"
contus2List[3] = "Flight Level 24,000"
contus2List[4] = "Flight Level 30,000"
contus2List[5] = "Flight Level 34,000"
contus2List[6] = "Flight Level 39,000"
contus2List[7] = "Flight Level 45,000"
// Hazards and High Level Significant Weather
contus3List[0] = "US Turbulence Report"
contus3List[1] = "US Convective SIGMENTS"
contus3List[2] = "US Convective Outlook"
contus3List[3] = "US Icing Reports"
contus3List[4] = "US Icing 12 Hour Forcast"
contus3List[5] = "US High Level Significant Weather Forecast"
// change options
function setLang(which) {
var listObj = document.forms[0].level
// find out how many entries
var listLength = listObj.length
//replace individual existing entries
for (var i = 0; i < listLength; i++) {
if (which == "contus1") {
listObj.options[i].text = contus1List[i]
} else if (which == "contus2") {
listObj.options[i].text = contus2List[i]
} else if (which == "contus3") {
listObj.options[i].text = contus3List[i]
}
}
if (navigator.appName == "Netscape") {
history.go(0)
}
}
// create entirely new object list
function setCount(choice) {
var listObj = document.forms[0].level
// get language setting
var lang
if (document.forms.wx[0].checked) {
lang = "contus1"
} else if (document.forms[0].wx[0].checked) {
lang = "contus2"
} else if (document.blah.wx[0].checked) {
lang = "contus3"
}
// empty options from list
listObj.length = 0
// create new option object for each entry
for (var i = 0; i < choice.value; i++) {
if (lang == "contus1") {
listObj.options[i] = new Option(contus1List[i])
} else if (lang == "contus2") {
listObj.options[i] = new Option(contus2List[i])
} else if (lang == "contus3") {
listObj.options[i] = new Option(contus3List[i])
}
}
listObj.options[0].selected = true
if (navigator.appName == "Netscape") {
history.go(0)
}
}
Choose One
Wind and Tempertures Aloft
Upper Air Analysis
Hazards and High Level Significant Weather
SubCatagory
Choose One
Mark Hensler posted this at 04:37 — 29th April 2001.
He has: 4,048 posts
Joined: Aug 2000
try changing the order from:
onClick="setLang('contus1');setCount(this)"
to:
onClick="setCount(this);setLang('contus1')"
The setCount() function creates enough tags in Then the setLang() changes the text for the existing tags.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.