I'm trying to concatenate a variable into a JQuery selector (which I understand to be fairly straightforward), but I'm running into some interesting behavior. My code is supposed to uncheck certain radio selectors along a y-axis.
for(var i = 1; i < 5; i++) {
$("input[value='"+1+"']").each(function() { //<--
$(this).on('change', function() {
var that = this;
$("input[value='"+1+"']").each(function() { //<--
if($(this).attr('name') != $(that).attr('name')) {
$(this).prop('checked', false);
}
});
});
});
}
Now, the code works as it is (selecting only inputs of value '1', that is) and works with the '1' included in the quotes as well. However, once I pass in either i or i.toString(), the code doesn't work. Ideally, I'd like to be able to pass in i to activate all my inputs. Is that going to be possible? I'm using JQuery from http://code.jquery.com/jquery-1.10.2.min.js.
HTML
<form method="POST" action="votes.php">
<div style="border:black solid 1px;border-radius:5px;">
<label>One</label>
<input type="radio" name="one" value="1">
<input type="radio" name="one" value="2">
<input type="radio" name="one" value="3">
<input type="radio" name="one" value="4">
</div>
<div style="border:black solid 1px;border-radius:5px;">
<label>Two</label>
<input type="radio" name="two" value="1">
<input type="radio" name="two" value="2">
<input type="radio" name="two" value="3">
<input type="radio" name="two" value="4">
</div>
<div style="border:black solid 1px;border-radius:5px;">
<label>Three</label>
<input type="radio" name="three" value="1">
<input type="radio" name="three" value="2">
<input type="radio" name="three" value="3">
<input type="radio" name="three" value="4">
</div>
<div style="border:black solid 1px;border-radius:5px;">
<label>Four</label>
<input type="radio" name="four" value="1">
<input type="radio" name="four" value="2">
<input type="radio" name="four" value="3">
<input type="radio" name="four" value="4">
</div>
</form>
nameon the radio belonging together)?