Testing Radio Button ON

I’m trying to verify if a Radio Button was clicked. Can’t find what is wrong with my code. There are no buttons checked and it does not return false and my next file get called (which is wrong).

[function formcheck(myform)
{with (myform)
var r=confirm(\"Are you sure you want to DELETE?\");
if (r==false){return false;}
var n = numrcds.value;
if(n<1){alert(\"DELETE is not possible since there are no records.\");return false;}     <------------------ works up to here.
if(choice.checked){return true;}
else{alert(\"At least one record must be selected in order to DELETE.\");return false;}}]

Same problem if I use:
[if(choice.checked==true){return true;}

My radio code is:
[<input type=“radio” name=“choice” id=“choice”>]

I’m not quite sure what I’m looking at here, and I certainly don’t know anything about JavaScript, but what if you tried referencing the choice element above the if statement?

var choice = document.getElementById("choice")

This is probably unnecessary, so maybe @Supun or @ckhawand can help.

1 Like

Why not just see if that guy is being handled properly? :sunglasses:

$('#choice').click(function() {
   if($('#choice').is(':checked')) { 
         alert("Radio button has been checked ;)");
    }
});

Thank you guys.
I found 2 statements wrong:
[var n = numrcds.value; changed to
var n = document.DeleteForm.numrcds;
if(choice.checked){return true;} changed to
if(id.choice==checked){return true;}]

Sorry guys. What I said is only good for the first statement.
The second statement
[if(id.choice==checked){return true;}]
still does not work.
I thought it worked but I later saw that I had an error in my test.

Did you try that?

$('#choice').click(function() {
   if($('#choice').is(':checked')) { 
         alert("Radio button has been checked ;)");
    }
});