•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,839 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,753 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1352 | Replies: 6 | Solved
![]() |
| |
•
•
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation:
Rep Power: 1
Solved Threads: 6
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:
and the html
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
This is the javascript:
javascript Syntax (Toggle Plain Text)
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
html Syntax (Toggle Plain Text)
<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
•
•
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation:
Rep Power: 5
Solved Threads: 71
•
•
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation:
Rep Power: 1
Solved Threads: 14
•
•
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation:
Rep Power: 5
Solved Threads: 71
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
•
•
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation:
Rep Power: 1
Solved Threads: 14
•
•
•
•
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:
<select name="states" id="states">
Otherwise you would have to use the getElementsByName() method to get all the elements with the name "states".
•
•
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation:
Rep Power: 1
Solved Threads: 6
thanks guys, this is how i fixed it:
javascript Syntax (Toggle Plain Text)
if (opt=="none"){document.f.states.disabled=true} else {document.f.states.disabled=false}
Last edited by hooray : Jan 21st, 2008 at 7:08 pm.
> Otherwise you would have to use the getElementsByName() method to get all the elements
> with the name "states".
Or simply
> with the name "states".
Or simply
document.forms[0].elements["states"].disabled = false; which is the correct way of handling form elements. I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- Recent changes (DaniWeb Community Feedback)
- Shut Down And Saving Your Settings (Windows NT / 2000 / XP / 2003)
- Pop-up "Messenger Service" HELP! Please. (Viruses, Spyware and other Nasties)
- Pop up ads to buy Spyware and Homepage changed. (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Works in FF, not in IE7
- Next Thread: Need to create an Event Calendar for company website



Hybrid Mode