3

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>
2
  • checking all radio button value means Commented Apr 19, 2013 at 7:13
  • it means im selecting radio button. @ PSR Commented Apr 19, 2013 at 7:17

4 Answers 4

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

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

Sign up to request clarification or add additional context in comments.

Comments

2

This might help.

$("input:checked").removeAttr("checked");

Comments

1

You can use a unique id for each radio button like:

<input type="radio" name="rdo1" id="rdo1_a" value="a" checked="checked" />

Now in the function:

function ResetRdo() {
    $("#rdo1_a").attr('checked') == 'checked';
}

Use the same case for each set.

2 Comments

May be you have to use a class instead of Id, Not a good idea to use same id for all.
@ssilas777 I said a unique id for each radio button. The code snippet is just an example.
1

You can give id for check boxes then do

  function reset(){ 
   $("#id").attr('checked', 'checked');
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.