Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how we add or remove readonly attribute from textbox on clicking radion button in cakephp using jquery?

Tags:

jquery

cakephp

Here is my cakephp generated HTML radio box and text box script:

<input type="radio" id="need_staff_on_site" name="data[CaterRequest][need_staff_on_site]" value="yes" class="staff_on_site"><span>Yes</span>  <input type="radio" id="need_staff_on_site" name="data[CaterRequest][need_staff_on_site]" class="staff_on_site" value="no"><span>No</span>  How many staff?<input type="text" maxlength="3" id="no_of_staff" name="data[CaterRequest][staff_needed]" class="txtboxSml2" readonly="readonly"> 

jquery Script:

$(document).ready(function(){    $('.staff_on_site').click(function(){    $arr=$(this).val();    if($arr == "yes"){ $("#no_of_staff").removeAttr("readonly"); }    if($arr == "no"){ $("#no_of_staff").attr("readonly", "readonly"); }   }); }); 

Demo jsfiddle Link

like image 823
Pank Avatar asked Sep 04 '12 07:09

Pank


People also ask

How do I remove the Read-Only property of a TextBox using jQuery?

$("#<%fieldname. ClientID%>"). attr("readonly","false");

How do I set the Read-Only attribute in jQuery?

Use jQuery methods to add the readonly attribute to the form input field. jQuery attr() Method: This method set/return attributes and values of the selected elements. If this method is used to return the attribute value, it returns the value of the first selected element.

How make readonly TextBox editable using jQuery?

$('input[type="text"], textarea'). attr('readonly','readonly'); 0.


1 Answers

In your Case you can write the following jquery code:

$(document).ready(function(){     $('.staff_on_site').click(function(){       var rBtnVal = $(this).val();       if(rBtnVal == "yes"){          $("#no_of_staff").attr("readonly", false);       }      else{           $("#no_of_staff").attr("readonly", true);       }    }); }); 

Here is the Fiddle: http://jsfiddle.net/P4QWx/3/

like image 171
Arun Jain Avatar answered Sep 29 '22 00:09

Arun Jain