Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable textbox using jquery?

Tags:

jquery

I have three radio buttons with same name and different values.When I click the third radio button the checkbox and textbox going to be disabled.but when I choose other two radio buttons it must be show.I need the help in Jquery.Thanks in advance....

<form name="checkuserradio">     <input type="radio" value="1" name="userradiobtn" id="userradiobtn"/>      <input type="radio" value="2" name="userradiobtn" id="userradiobtn"/>     <input type="radio" value="3" name="userradiobtn" id="userradiobtn"/>     <input type="checkbox" value="4" name="chkbox" />     <input type="text" name="usertxtbox" id="usertxtbox" /> </form> 
like image 280
svk Avatar asked Oct 30 '09 09:10

svk


People also ask

How do I disable a textbox?

We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.

How check textbox is enabled or disabled in jQuery?

You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") .

How do I set disabled property in jQuery?

The disable/enable an input element in jQuery can be done by using prop() method. The prop() method is used to set or return properties and values for the selected elements.

How do I GREY out a textbox in JavaScript?

document. getElementById("name"). disabled = true; This the best solution for my applications - hope this helps!


1 Answers

HTML

<span id="radiobutt">   <input type="radio" name="rad1" value="1" />   <input type="radio" name="rad1" value="2" />   <input type="radio" name="rad1" value="3" /> </span> <div>   <input type="text" id="textbox1" />   <input type="checkbox" id="checkbox1" /> </div> 

Javascript

  $("#radiobutt input[type=radio]").each(function(i){     $(this).click(function () {         if(i==2) { //3rd radiobutton             $("#textbox1").attr("disabled", "disabled");              $("#checkbox1").attr("disabled", "disabled");          }         else {             $("#textbox1").removeAttr("disabled");              $("#checkbox1").removeAttr("disabled");          }       });    }); 
like image 108
o.k.w Avatar answered Sep 19 '22 02:09

o.k.w