I have these 2 checkboxes:
<form action="">
<input id="bikeCheckbox" type="checkbox" name="bikeCheckbox" value="Bike">I have a bike<br>
<input id="carCheckbox" type="checkbox" name="carCheckbox" value="Car">I have a car
</form>
The events for each checkbox:
jQuery(function () {
$("#carCheckbox").click(function () {
if($("#carCheckbox").is(":checked")) {
alert("it works");
}
})
});
jQuery(function () {
$("#carCheckbox").click(function () {
if($("#bikeCheckbox").is(":checked")) {
alert("it works");
}
})
});
Now what I want to do is create a for or some kind of loop to create event handlers for multiple checkboxes. So far I am stuck at this code:
jQuery(function () {
var infoArray = ["car", "bike"];
for(var i = 0; i < infoArray.length; i++) {
var id = "#" + infoArray[i] + "Checkbox";
$(id).click(function () {
var myCheckbox = "#" + infoArray[i] + "Checkbox;
if($(myCheckbox).is(":checked")) {
alert("it works");
}
})
}
});
Any help is greatly appreciated.