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 }); 
  1. id should unique
  2. don't need for bind event
  3. you cannot return event handlers
  4. use insert inside event handler

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -