This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I disable a text input field?

 
Anonymous
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.
Help!
 
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:
<SCRIPT LANGUAGE="JavaScript">
<!--
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;
}
// -->
</SCRIPT>
<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>
</FORM>

You can get a more thourough description by following this link: http://www.webreference.com/js/tips/991030.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic