• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I disable a text input field?

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic