un-disable dropdown box
Hi I have some code here that fills a dropdown box from an array depending on what is selected in another dropdown box. One of them is disabled, and i would like to stop that once an option has been selected.
This is the Javascript:
function fillStates(opt){
s=document.f.states.options
s.length=stateNames[opt].length
for(i=0;i<s.length;i++){
s[i].value=stateNames[opt][i]
s[i].text=stateNames[opt][i]
}
document.f.states.selectedIndex=0
}
and the html
<form name="f">
<select name=countries onChange="fillStates(this.options[this.selectedIndex].value)">
<? echo $optionc; ?>
</select>
<select name=states disabled="disabled">
<option>Choose a country first</option>
</select>
</form>
if anyone could give me a way to remove the disabled part on the second box once an option in the first box has been selected I would be grateful.
Thanks
hooray
Junior Poster in Training
62 posts since Jan 2008
Reputation Points: 11
Solved Threads: 6
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
document.getElementById('states').disabled=false;
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
document.getElementById('states').disabled=false;
That won't work. The selectbox doesn't have an ID, set the ID to states then do the above for it to work.
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
thanks guys, this is how i fixed it:
if (opt=="none"){document.f.states.disabled=true}
else {document.f.states.disabled=false}
hooray
Junior Poster in Training
62 posts since Jan 2008
Reputation Points: 11
Solved Threads: 6
That won't work. The selectbox doesn't have an ID, set the ID to states then do the above for it to work.
yes shawnCplus is right! change name to id or just simply add id as in:
Otherwise you would have to use the getElementsByName() method to get all the elements with the name "states".
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
> Otherwise you would have to use the getElementsByName() method to get all the elements
> with the name "states".
Or simply document.forms[0].elements["states"].disabled = false; which is the correct way of handling form elements.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733