jquery - Passing Variable between JavaScript click handlers -


how pass variable in javascript click handlers.

i have assigned var condition_selction = ($(this).val()); in .change(function). how can value of variable in second click handle $( "#process-signs-scrap-scrapped-button-enabled" ).click(function() {.

how pass variable between these 2 functions.

$('input:checkbox').change(function() {         /*get parent node of radio , hide siblings*/         $(this).parent('label').siblings().toggle();         if ($('.sign-condition').is(':checked')) {             var condition_selction = ($(this).val());         }         if ($('.sign-reason').is(':checked')) {             var reason_selction = ($(this).val());         }         //check both select fields have value         if (condition_selction != null && reason_selction != null) {             $("#process-signs-scrap-scrapped-button-disabled").hide();             $("#process-signs-scrap-scrapped-button-enabled").show();         } else {             $("#process-signs-scrap-scrapped-button-disabled").show();             $("#process-signs-scrap-scrapped-button-enabled").hide();         }     });      $( "#process-signs-scrap-scrapped-button-enabled" ).click(function() {                var process_signs_scrap_condition = condition_selction;               var process_signs_scrap_reason = reason_selction               // open timer modal             $('#process-signs-scrap-scrapped-modal').modal('show'); 

declare both var globally, can access them in both functions

var condition_selction; // var reason_selction;  $('input:checkbox').change(function() {     /*get parent node of radio , hide siblings*/     $(this).parent('label').siblings().toggle();     if ($('.sign-condition').is(':checked')) {         condition_selction = ($(this).val()); // removed declaration      }     if ($('.sign-reason').is(':checked')) {         reason_selction = ($(this).val());     }     //check both select fields have value     if (condition_selction != null && reason_selction != null) {         $("#process-signs-scrap-scrapped-button-disabled").hide();         $("#process-signs-scrap-scrapped-button-enabled").show();     } else {         $("#process-signs-scrap-scrapped-button-disabled").show();         $("#process-signs-scrap-scrapped-button-enabled").hide();     } });  $( "#process-signs-scrap-scrapped-button-enabled" ).click(function() {            var process_signs_scrap_condition = condition_selction;           var process_signs_scrap_reason = reason_selction           // open timer modal         $('#process-signs-scrap-scrapped-modal').modal('show'); 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -