User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation: hooray is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Help un-disable dropdown box

  #1  
Jan 21st, 2008
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:

  1. function fillStates(opt){
  2. s=document.f.states.options
  3. s.length=stateNames[opt].length
  4. for(i=0;i<s.length;i++){
  5. s[i].value=stateNames[opt][i]
  6. s[i].text=stateNames[opt][i]
  7. }
  8. document.f.states.selectedIndex=0
  9. }

and the html
  1. <form name="f">
  2. <select name=countries onChange="fillStates(this.options[this.selectedIndex].value)">
  3. <? echo $optionc; ?>
  4. </select>
  5. <select name=states disabled="disabled">
  6. <option>Choose a country first</option>
  7. </select>
  8. </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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 71
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: un-disable dropdown box

  #2  
Jan 21st, 2008
<listbox>.disabled = false
Last edited by ShawnCplus : Jan 21st, 2008 at 3:59 pm.
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+*
Reply With Quote  
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation: johnsquibb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

  #3  
Jan 21st, 2008
document.getElementById('states').disabled=false;
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 71
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: un-disable dropdown box

  #4  
Jan 21st, 2008
Originally Posted by johnsquibb View Post
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.
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+*
Reply With Quote  
Join Date: Nov 2007
Location: Las Vegas, Nevada
Posts: 83
Reputation: johnsquibb is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

  #5  
Jan 21st, 2008
Originally Posted by ShawnCplus View Post
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".
Reply With Quote  
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation: hooray is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

  #6  
Jan 21st, 2008
thanks guys, this is how i fixed it:

  1. if (opt=="none"){document.f.states.disabled=true}
  2. else {document.f.states.disabled=false}
Last edited by hooray : Jan 21st, 2008 at 7:08 pm.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,863
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: un-disable dropdown box

  #7  
Jan 23rd, 2008
> 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.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC