Hi, basically I'm trying to pass a variable that is defined in a JSON array that is parsed through in a for loop to be accessible in a click statement.
$(document).ready(function() {
getJSON();
var usedID;
});
function readJSON() {
for (var i = 0; i < json.array.length; i ++) {
usedID = json.array[i].id;
var template = $('repeaterTemplate').clone();
template.removeAttr('id');
template.attr('id', 'k' + json.array.id);
var omega = json.array.id;
$('#repeater').append(template);
(function(o) {
$('#' + o).click(function() {
// this is where the submitID click function is now. It passes the omega value in
});
})(omega);
}
}
$('.submitID').click(function() {
submitNow(usedID);
}
Right now I have the submitID click function in my for loop and it's causing the submitNOW function to be called however many times the loop cycles through. Can anyone help me with passing the userID from the readJSON() to the click function?
I'm getting a parse error with your each function:
var userID = [];
var j = 0;
$('.submitNOW').each(function() {
function(id) {
$(this).click(function() {
submitNow(id);
});
}(userID[j]);
});