javascript - Unable to return value in scoped for loop: jQuery -
i have problem in jquery value in insert still returns null when running code below. i'm running through salesforce's exact target , has html document , script doc, contains code snippet below.
var value = "subscriptions are: "; var insert = null;
for (var = 0; < 10; i++) { $("#lol").click(function() { if($(this).prop("checked") == true) { insert = "lol"; return insert; } }) }; value = value + insert;
in instance, data receive in exact target gives me "subscription is: null". checkbox checked , not give me anything. believe scoping problem?
update:
$("#lol").click(function() { if($(this).prop("checked") == true) { console.log("lol"); insert = "lol"; } });
will produce same error
$("#lol").on('click', function() { if ($(this).prop("checked") == true) { insert = "lol"; } value += insert; alert(insert); // use `insert` here });
id
shouldunique
- don't need
for
bind event - you cannot return
event
handlers - use
insert
insideevent
handler
Comments
Post a Comment