Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enable disabled input using js

 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have two text inputs that i want to be disabled unless a particular radio button is checked. how do i do this?
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Randall,
afaik is there no special js-function for enabling an disabled (set readonly) inputfield.
I'd do it this way:

Only tested in IE6 !
hth cb
[ May 25, 2003: Message edited by: Christian Baron ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Acyually it can be done using the disabled attribute of the element
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is a radio button not a checkbox. i will look over erics code though. i see...the documentation didnt say you could assign true or false to the disabled attribute
i guess i could put an onclick in each of my radio buttons and, in the script, set the attribute true or false depending on the value of the radio button. unless there is an easier way
[ May 25, 2003: Message edited by: Randall Twede ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code should not be that much different from the radio button, yeah, the disabled attribute can be handled that way, but the readonly on can not be changed with true or false which makes me wonder why it exsists!
Eric
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess i could put an onclick in each of my radio buttons and, in the script, set the attribute true or false depending on the value of the radio button. unless there is an easier way
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it...thanks eric..you too christian..the script ended up looking like this:

tab order works right and everything
[ May 25, 2003: Message edited by: Randall Twede ]
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
disabling inputs is the exception rather than the norm, so if you are curious, this is a homework assignment to make a complaint form. i will post the entire code for any that are curious about why i wanted to disable the two text inputs.

[ May 25, 2003: Message edited by: Randall Twede ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking of a trickier way to do it without all of the onclicks, I know a way to do it, but it adds alot of code. Well see if I can scrounge something up.
but I would use onblur or onfocus instead of onclick incase they use the tab key and arrow keys!
[ May 25, 2003: Message edited by: Eric Pascarello ]
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it seems to work fine with the tab key...if the right radio button is not selected, it skips the textboxes
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what I am saying is this
tab to the radio buttons, push the arrow key and select the right one that will show the field. then push tab....see what i am talking about?
Eric
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh..i see what you mean, but it works anyway (at least in IE). if i tab to the radio buttons, then arrow to the one that enables the two textboxes, then hit tab, the first (formerly disabled) textbox gets the focus.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thought I would point that out, do not want you to loose points...lol
 
Randall Twede
Ranch Hand
Posts: 4442
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol...the script is a "bonus" feature not actually required. i think i will change it as suggested anyway as it might not work correctly with all browsers when not using a mouse.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic