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!
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.
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.
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
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