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
$("#<%fieldname. ClientID%>"). attr("readonly","false");
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.
$('input[type="text"], textarea'). attr('readonly','readonly'); 0.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With