un-disable dropdown box

Thread Solved

Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

un-disable dropdown box

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,538
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 255
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: un-disable dropdown box

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: johnsquibb is an unknown quantity at this point 
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

 
0
  #3
Jan 21st, 2008
document.getElementById('states').disabled=false;
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,538
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 255
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: un-disable dropdown box

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

 
0
  #5
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 Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: johnsquibb is an unknown quantity at this point 
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: un-disable dropdown box

 
0
  #6
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 Quick reply to this message  
Join Date: Jun 2006
Posts: 7,764
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 492
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: un-disable dropdown box

 
0
  #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.

Sacrifice is a painful, pure and beautiful thing.

Dammit, Jones, What the Hell Are Knoll Pointers?!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



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


Views: 2776 | Replies: 6
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC