Inside my for loop that loops through 15 "box" objects, code below:
for (var i = 0; i < boxesLength; i++) {
I'm trying to generate these click events automatically, they used to be like this: (all the way up until 15)
$("#box0").click(function(){
var rw = 462;
var input = $('#rw');
input.val(rw);
var rh = 310;
var input = $('#rh');
input.val(rh);
calculateRectangle();
calculateRectangle2();
});
Right now I am trying to auto-generate these in the for loop by doing this:
$("#box" + i).click(function(){
var rw = allBoxes[i].width;
var input = $('#rw');
input.val(rw);
var rh = allBoxes[i].length;
var input = $('#rh');
input.val(rh);
calculateRectangle();
calculateRectangle2();
});
What am I doing wrong? When I console log "#box" + i I am getting the expected result..