javascript - Value not changing in onchange -


in page i'm having multiviews. when user add button in 1st view, transfers 2nd view. in 2nd view having full of text boxes filling. if enters text , tries go away without saving. prompt should come keep changes or navigate away. functionality had done following code. whenever user onchange of textbox in form i'm changing hiddenfield(taken hidden field indicates whether having dirty data or not) value 0 1.

but i'm unable access hidden field value in function.

var = 0; $(function() {     $("input[type='text']").change(function() {         $("#testhidden").val("1"); //changed hidden field value 1         = 1; // changed value         console.log("a " + a);         console.log("testhidn value " + $("#testhidden").val());     }); }); $(function() {     alert(a); //always getting "a" value "0" though changed.      if (window.history && window.history.pushstate) {         if (a == 1) {             $(window).on('popstate', function() {                  var hashlocation = location.hash;                 var hashsplit = hashlocation.split("#!/");                 var hashname = hashsplit[1];                  if (hashname !== '') {                     var hash = window.location.hash;                     if (hash === '') {                         alert('back button pressed.');                     }                     if (a == 1) {                         alert("a if part 1" + a);                     } else {                         alert("a else part 1" + a);                     }                     window.history.pushstate('forward', null, '#');                 }              });             window.history.pushstate('forward', null, '#');             if (a == 1) {                 alert("a if part 2" + a);             } else {                 alert("a else part 2" + a);             }         }     } }); 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -