This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.

Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!

Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I disable a text input field?  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two radio buttons and under each radio button I have few text input fields. I need to disable the text fields based on the radio option selection.
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem you are going to run into is that only IE4 and above support diabling form fields, but with that said, here is how you do it in IE.
You are going to have a Javascript function that is activated on the radio button's, onMouseUp event. The function will look at the value of the radio field and then look at the disabled value of the text box. If the radio button is "Yes" for example, and the text box is disabled, you enable it, and vice versa. Here is the code:
var IE4 = (document.all) ? 1 : 0;
function enableText() {
if (!IE4) return;
var form = document.myForm;
var currentState = form.myText.disabled;
var changeState = form.myRadio.value;
if (changeState != currentState)
form.myText.disabled = changeState;
// -->
<FORM NAME="myForm">
<INPUT TYPE="radio" name="myRadio" value=true CHECKED onMouseUp="enableText()">Disable
<INPUT TYPE="radio" name="myRadio" value=false onMouseUp="enableText()">Enable
<INPUT TYPE="text" NAME="myText" SIZE="30" DISABLED>

You can get a more thourough description by following this link:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!