I have a form which contains data that will be dynamically added to my form. Once the data has been added, I would like to verify the value (specifically if a radio button has been checked) of a radio button and then do different things based on which radio button is checked.
Currently, I am unable to do so as no matter the state of the radio button (i.e checked OR unchecked) I am always getting the alert ("Button is no checked").
Code:
<!DOTYPE HTML>
<html>
<head>
<link type='text/css' rel='stylesheet' href='style.css'>
<!--jQuery Validation-->
<!--Loads JQuery and JQuery validate plugin-->
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type='text/javascript'>
$(document).ready(function ()
{
function checkradio(radio)
{
if (radio.checked)
{
alert("no is checked");
}
else
{
alert("no is not checked");
}
}
function radiocheck()
{
checkradio($('#no'));
}
$('#submit1').click(function ()
{
radiocheck();
})
});
</script>
</head>
<body>
<input type='radio' id='yes' name='radiobutton' value='yes'>yes
<input type='radio' checked='checked' id='no' name='radiobutton' value='no'>no
<input type='button' id='submit1' name='submit' value='submit'>
</body>
</html>