Easier to show than explain.
I've got an HTML page with a bunch of drop-down lists (<SELECT> tags). There's a dropdown for each state. Each drop down contains <OPTION> for each county within that sate.
I have another drop down list of each state:
Basically, when the user selects a state, the ShowCounty() javascript function will:
1. hide all <SELECT> inputs with a "county[]" ID
2, show the <SELECT> input with the ID "county[document.all.states.value]"
The problem I'm running into is that Javascript doesn't seem to like using my SELECT tags that have array IDs. I can't even get the value of the drop-downs:
command: alert(document.all.county[AL].value);
error: 'AL' is undefined.
command: alert(document.all.county['AL'].value);
error: 'document.all.county.AL' is null or not an object.
I'd also like to be able to for-each through the array, but can't figure out how to do it Java Script.
For example in PHP I could:
Is JavaScript incapable of dealing with objects with array names? If so, tell me what I need to do, please.
Thanks in advance!
-Jeff
"Grace... She travels outside of Karma"
-U2
I've got an HTML page with a bunch of drop-down lists (<SELECT> tags). There's a dropdown for each state. Each drop down contains <OPTION> for each county within that sate.
Code:
<SELECT NAME="county[AK]" ID="county[AK]">
<OPTION>Alaska county 1</OPTION>
<OPTION>Alaska county 2</OPTION>
<OPTION>Alaska county 3</OPTION>
...
</SELECT>
<SELECT NAME="county[AL]" ID="county[AL]">
<OPTION>Alabama county 1</OPTION>
<OPTION>Alabama county 2</OPTION>
<OPTION>Alabama county 3</OPTION>
...
</SELECT>
I have another drop down list of each state:
Code:
<SELECT NAME="states" ID="states" onChange="ShowCounty()">
<OPTION VALUE="AK">AK - Alaska</OPTION>
<OPTION VALUE="AL">AL - Alabama</OPTION>
...
</SELECT>
Basically, when the user selects a state, the ShowCounty() javascript function will:
1. hide all <SELECT> inputs with a "county[]" ID
2, show the <SELECT> input with the ID "county[document.all.states.value]"
The problem I'm running into is that Javascript doesn't seem to like using my SELECT tags that have array IDs. I can't even get the value of the drop-downs:
command: alert(document.all.county[AL].value);
error: 'AL' is undefined.
command: alert(document.all.county['AL'].value);
error: 'document.all.county.AL' is null or not an object.
I'd also like to be able to for-each through the array, but can't figure out how to do it Java Script.
For example in PHP I could:
Code:
foreach ($county as $key => $value)
{
// $key would return the array key
// $value would return the value
}
Is JavaScript incapable of dealing with objects with array names? If so, tell me what I need to do, please.
Thanks in advance!
-Jeff
"Grace... She travels outside of Karma"
-U2