1

am having the code as follows when clicked on radio button yes the text box has to be enabled if not it has to be disabled. please someone help me. thanks

<div class="label_left">
    <label>Does the tourism office operate on a biennial budget? : (Y/N)</label>
</div>
<div class="text_right">
    <br>
    <br>
    <input type="radio" id="high" name="high" />
    <label>Y</label>&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="radio" id="high" name="high" />
    <label>N</label>
    <br />
    <br />
    <br />
</div>
<div class="label_left">
    <label>If YES,please indicate when the current biennial budget began: (mm/dd/yy)</label>
</div>
<div class="text_right">
    <br>
    <br>
    <input type="text" name="date_biennial_budget" id="date_biennial_budget" value="" size="30" />
    <br />
    <br />
    <br />
</div>
Tushar Gupta - curioustushar
  • 54,013
  • 22
  • 95
  • 103
user2412936
  • 341
  • 2
  • 6
  • 16

4 Answers4

6

first of all make sure your id is unique..

use prop() to enable/disable elements.. (make sure you add value to your radio button... which is missing in your code )

HTML

<input type="radio" id="high" value="Y" name="high"  />
<input type="radio" id="high" value="N" name="high"  />

jquery

 $('input[name="high"]').change(function(){
      if($(this).val() == 'Y'){
         $('#date_biennial_budget').prop('disabled',false);
      }else{
         $('#date_biennial_budget').prop('disabled',true);
      }
 });
bipen
  • 34,730
  • 9
  • 44
  • 61
3

It's easy with jQuery > 1.6

$('input').prop('disabled',true)
$('input').prop('disabled',false)

To react to your radio button, you have to give each one a different value attribute (1 for yes?) and listen to the change event.

$("#date_biennial_budget").change(function(){

    if($(this).val() == 1) 
       $('input[name=high]').prop('disabled',false);
    else 
       $('input[name=high]').prop('disabled',true);
}
Human Being
  • 7,671
  • 25
  • 86
  • 134
Armel Larcier
  • 14,350
  • 7
  • 62
  • 86
1
if($('#high').is(":selected") {
   $('input').prop('disabled',true);
} else {
   $('input').prop('disabled',false);
}

try this

0

Use this for text-box,

$('input[type=text]').prop('disabled',true);

UPDATES: Since you have used label tag, you use for attribute like below

<input type="radio" id="highY" name="high" />
<label for="highY">Y</label>
<input type="radio" id="highN" name="high" />
<label for="highN">N</label>

Assign the id of the respective input to the for attribute in label

Based on this you can do like this

$('input[name=high]').on('change', function () {
    var label = $('label[for=' + this.id + ']').text();
    if (label === "Y") {
        $('#date_biennial_budget').prop('disabled', false);
    } else {
        $('#date_biennial_budget').prop('disabled', true);
    }
});

JSFiddle

Praveen
  • 50,562
  • 29
  • 125
  • 152