Reputation: 10012
I have the following jsfiddle:
I want to alert the value of the second radio button form. But if I select a value from the first form, it's value appears in the alert instead of the second form's value.
html:
<form id="formOne">
New invoice <input id="radioNewInvoice" name="groupOne" type="radio" value="new"></input>
Modify existing invoice<input id="radioModInvoice" name="groupOne" type="radio" value="mod"></input>
</form>
<form id="form2">
<input id="normal" type="radio" name="groupTwo" value="normal" /> normal <br>
<input id="30days" type="radio" name="groupTwo" value="30days" /> 30 days <br>
<input id="60days" type="radio" name="groupTwo" value="60days" /> 60 days <br>
<input id="90days" type="radio" name="groupTwo" value="90days" /> 90 days <br>
<input id="90pdays" type="radio" name="groupTwo" value="90+days" /> 90+ days <br>
</form>
<input id="but" type="button" value="click" />
javascript:
$('#but').click(function() {
alert($("input[@name=groupTwo]:checked").val());
});
Upvotes: 0
Views: 2580
Reputation: 17566
alert($('input[name=groupTwo]:radio:checked').val());
this works fine :D
Upvotes: 1
Reputation: 5681
Change your alert to
alert($("#form2 input:checked").val());
It's the quick and dirty solution, but it works.
Upvotes: 1
Reputation: 24198
$('#but').click(function(){
alert($("input[name*='groupTwo']:checked").val());
});
Upvotes: 1
Reputation: 3406
$("#but").click(function() {
alert($("#form2 input:checked").val());
});
Upvotes: 2
Reputation: 5912
use this:
alert($('input[name=groupTwo]:checked').val());
or to get a specific form:
alert($('input[name=groupTwo]:checked', '#form2').val());
Upvotes: 2
Reputation: 270599
Rmove the @
from the input selector.
$('#but').click(function(){
alert($("input[name=groupTwo]:checked").val());
});
Upvotes: 4
Reputation: 10638
$('#but').click(function(){
alert($("#form2 input[@name=groupTwo]:checked").val());
});
Upvotes: 1