I am confused about this code its self explanatory what its supposed to do but it doesn’t do it
<input name="property" type="radio" checked value="1" />Station Masters House
<input name="property" type="radio" value="2" />Railway Carriage
<br><br>
<div id="fillin">press</div>
$("#fillin").click(function() {
if ($('input[name=property]').val() == "1")
{
alert($('input[name=property]').val());
} else if ($('input[name=property]').val() == "2") {
alert($('input[name=property]').val());
}
});
example here
input[name=property].length === 2… therefore,.val()won’t work. (.valpulls the value of the first element in the DOM that it finds that matches the requested selector, except in the case of a<select multiple>element.)Try
input[name=property]:checkedinstead.Better yet, cache the things you need, so you are only hitting the DOM (or in this case, jQuery’s cache) once: