Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable input fields if radio buttons is checked with jquery

I have this radio buttons in html code:

<span><input type="radio" value="false" name="item[shipping]" id="item_shipping_false" checked="checked"><label for="item_shipping_false" class="collection_radio_buttons">No</label></span>

<span><input type="radio" value="true" name="item[shipping]" id="item_shipping_true"><label for="item_shipping_true" class="collection_radio_buttons">Yes</label></span>

and I have 1 disabled field like:

<input id="item_shipping_cost" class="currency optional" type="text" size="30" name="item[shipping_cost]" disabled="disabled">

I want that if an user click in option Yes in radio buttons, remove the html attributedisabled="disabled" to this last input field, and if user click in option No in radio buttons add the attributedisabled="disabled" to this last input field

How can I do it with jquery?

thank you!

like image 937
hyperrjas Avatar asked May 08 '12 11:05

hyperrjas


People also ask

Do something when radio button is checked jQuery?

We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.

How do you check if radio button is checked or not?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.


1 Answers

you can use removeAttr

   $('#item_shipping_true').click(function()
{
  $('#item_shipping_cost').removeAttr("disabled");
});

$('#item_shipping_false').click(function()
{
  $('#item_shipping_cost').attr("disabled","disabled");
});

see demo in JsFiddle

like image 121
Ravi Gadag Avatar answered Nov 15 '22 06:11

Ravi Gadag