javascript - jQuery variable doesn't evaluate as expected -


i working on creating jquery script data flow window variable used determine path script should proceed with. expected path this:

  • initial function sets variable, window.questionselector 0, -1, or number
  • the value of window.questionselector @ 0 means new parent quiz, -1 means new question, , number means existing question referred to.

this code calls question function

 $(".questionjumplink").click(function () {             //questionjumplink have data-attribute attached if you're selecting different question              if ($(this).attr('data-questionid')) {                 window.questionselector = $(this).attr('data-questionid');                 console.log("question id " + window.questionselector + " requested");             }               if (window.questionselector == -1) {                 console.log("new question request detected");             }      questionfunction(); } 

this if statement, part of questionfunction(), triggered despite fact value of window.questionselector -1.

 //used when navigating between questions, not on initial load. questionselector  //is questionid being requested. -1 can set new question indicator  if (window.questionselector != 0 && window.questionselector != -1)  {      console.log("question switch, same quiz path switch");     //some code , handling, not vital } 

this if statement, directly below above code block in questionfunction(), 1 expect triggered:

 if (window.questionselector != 0 && window.questionselector === -1) {      console.log("new question path");      $("#quizquestion").unbind();       $("#quizquestion").focusout(function () {      questionfield();      console.log("build answers called");      buildanswers();      $("input[name^=answerorder]").unbind();      enableanswerordersave();      $("[name^=answerid]").unbind();      autocheckboxonchange();      $("input[id^=isvalidanswer]").unbind();      answeracdeac();      $("input[name^=iscorrectanswer]").unbind();      answercorrectupdate();      })  } 

going == or === seems make no difference. i've verified in debugger window.questionselector equals -1.

the problem variable being set string, evaluates differently int.

in declaring variable had modify code using parseint function.

window.questionselector = parseint($(this).attr('data-questionid')); 

then evaluation worked expected.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -