I have this HTML:
<input type="radio" name="test" id="test" value="1"><br>
<input type="radio" name="test" id="test" value="2"><br>
<input type="radio" name="test" id="test" value="3"><br>
<input type="button" onclick="CreateJobDo">
When the page loads, none of them will be checked. I want to use jQuery to check if one of the radio buttons is checked when the button is pressed.
I have this:
function CreateJobDo(){
if ($("input[@name=test]:checked").val() == 'undefined') {
// go on with script
} else {
// NOTHING IS CHECKED
}
}
But this does not work. How to get it working?
This question is related to
jquery
$('#submit_button').click(function() {
if (!$("input[@name='name']:checked").val()) {
alert('Nothing is checked!');
return false;
}
else {
alert('One of the radio buttons is checked!');
}
});
First of all, have only one id="test"
Secondly, try this:
if ($('[name="test"]').is(':checked'))
if($("input:radio[name=test]").is(":checked")){
//Code to append goes here
}
Something like this:
$("input[name=test]").is(":checked");
Using the jQuery is() function should work.
Source: Stackoverflow.com