Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset radio button using jQuery

I'm have multiple radio button. After check or select radio button value randomly, i need to reset radio button to default checked or selected value on button click. My HTML code is below.

jQuery

function ResetRdo() {
    // Code to reset ?
}

HTML

<table>
    <tr>
        <td>
            <input type="radio" name="rdo1" value="a" checked="checked" />
            A
            <input type="radio" name="rdo1" value="b" />
            B
            <input type="radio" name="rdo1" value="c" />
            C
        </td>
    </tr>
    <tr>
        <td>
            <input type="radio" name="rdo2" value="1" />
            1
            <input type="radio" name="rdo2" value="2" checked="checked" />
            2
            <input type="radio" name="rdo2" value="3" />
            3
        </td>
    </tr>
    <tr>
        <td>
            <input type="radio" name="rdo3" value="1a" />
            1a
            <input type="radio" name="rdo3" value="2b"  />
            2b
            <input type="radio" name="rdo3" value="3c" checked="checked" />
            3c
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" value="Reset" onclick="ResetRdo()" />
        </td>
    </tr>
</table>
like image 952
Lakshmana Kumar Avatar asked Feb 05 '26 20:02

Lakshmana Kumar


2 Answers

$('input[type=radio]').prop('checked', function () {
    return this.getAttribute('checked') == 'checked';
});

Here's the fiddle: http://jsfiddle.net/DNUdv/

like image 94
Joseph Silber Avatar answered Feb 08 '26 11:02

Joseph Silber


This might help.

$("input:checked").removeAttr("checked");
like image 38
Anil Shrestha Avatar answered Feb 08 '26 11:02

Anil Shrestha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!