Click here to Skip to main content
15,168,105 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the code to uncheck radio button , but the problem is , its not happening in one click when the radio button is checked , i am fetching the value of radio button as checked from mysql , so the default value of radio button is checked and when i click on the radio button the value should uncheck upon single click but my code is making it happen on double click , how do i make it happen with single click ?

What I have tried:

<input type="radio" name="check" value="check" onClick="javascript:docheck(this);" checked="checked"/>

var check;

$('input[type="radio"]').hover(function() {
    check = $(this).is(':checked');

var checkedradio;
function docheck(thisradio) {
    if (checkedradio == thisradio) {
        thisradio.checked = false;
        checkedradio = null;
    else {checkedradio = thisradio;}

Updated 5-Apr-21 5:58am

1 solution

When you enter your function for the first time, what is the value of "checkedradio"?

You need to initialize it - which is tricky since it is the same value used for all the radio buttons ('this') that you call in this way (if you have more than one).

Meanwhile, radio buttons are designed to work in sets of two or more. You'd be in more stable territory if you simply made a "none of these" button. If there's only one button you should be using a checkbox.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900