I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call that variable in another Java script.
Sample script
<SCRIPT LANGUAGE="JavaS cript">
function GetSelectedItem () {
len = document.formna me.selectname.l ength
i = 0
chosen = "none"
for (i = 0; i < len; i++) {
if (document.formn ame.selectname[i].selected) {
chosen = document.formna me.selectname[i].value
}
}
//return chosen
alert(chosen);
}
</script>
I tried setting a global variable to equal "chosen" but when I run the page it tells me that global variable is undefined. So my question is how do I define a local variable to be equal to a global variable, so that when I leave the function "chosen" still has a value.
My best guess is the following script.
<SCRIPT LANGUAGE="JavaS cript">
function GetSelectedItem () {
len = document.zonepi ck.zonebox.leng th
i = 0
chosen = "none"
for (i = 0; i < len; i++) {
if (document.zonep ick.zonebox[i].selected) {
chosen = document.zonepi ck.zonebox[i].value;
_global.thezone = chosen;
}
}
//return chosen
//alert(chosen);
}
alert(thezone);
</script>
But sadly that scripts doesn't work. Any help would be greatly appreciated, even if you just give me a google phrase so that I can search the answer myself.
Ben
Sample script
<SCRIPT LANGUAGE="JavaS cript">
function GetSelectedItem () {
len = document.formna me.selectname.l ength
i = 0
chosen = "none"
for (i = 0; i < len; i++) {
if (document.formn ame.selectname[i].selected) {
chosen = document.formna me.selectname[i].value
}
}
//return chosen
alert(chosen);
}
</script>
I tried setting a global variable to equal "chosen" but when I run the page it tells me that global variable is undefined. So my question is how do I define a local variable to be equal to a global variable, so that when I leave the function "chosen" still has a value.
My best guess is the following script.
<SCRIPT LANGUAGE="JavaS cript">
function GetSelectedItem () {
len = document.zonepi ck.zonebox.leng th
i = 0
chosen = "none"
for (i = 0; i < len; i++) {
if (document.zonep ick.zonebox[i].selected) {
chosen = document.zonepi ck.zonebox[i].value;
_global.thezone = chosen;
}
}
//return chosen
//alert(chosen);
}
alert(thezone);
</script>
But sadly that scripts doesn't work. Any help would be greatly appreciated, even if you just give me a google phrase so that I can search the answer myself.
Ben
Comment