html - javascript not bringing user to redirected page -


hi im trying build user gets re directed new page here's code

var blue = ["question1button1", "question1button2"];  var secondquestion = ["question2button1", "question2button2"];  var button1, button2, button3, button4 = false;    function myfunction() {      var favorite = blue[math.floor(math.random() * blue.length)];      var postmessage = favorite;      document.getelementbyid("mybtn").value;      document.getelementbyid("demo").innerhtml = postmessage;        if (postmessage == "test"){      	button1 = true;      	alert("test");      }      if (postmessage == "test1"){          button2 = true;      	alert("test1");      }      if (postmessage == "test2"){          button3 = true;      	alert("test2");      }        if (postmessage == "test3"){          button4 = true;      	alert("test3");      }  }    function next(){      if(button1 == true || button2 == true){          window.location = "test/test1.html";      }      else{          alert("choose side");      }  }
<button id="mybtn" value="myvalue" onclick="myfunction()">try it</button>    <p id="demo"></p>  <button id="next1" value="gonext" onclick="next()">next</button>

so question here have pressed button it's still telling me else statement

its because condition in postmessage wrong.. change postmessage == "test" postmessage == "question1button2" or postmessage == "question1button1"

try code..

var blue = ["question1button1", "question1button2"];  var secondquestion = ["question2button1", "question2button2"];  var button1, button2, button3, button4 = false;    function myfunction() {    var favorite = blue[math.floor(math.random() * blue.length)];    var postmessage = favorite;    document.getelementbyid("mybtn").value;    document.getelementbyid("demo").innerhtml = postmessage;      if (postmessage == "question1button1"){      button1 = true;      alert("test");    }    if (postmessage == "question1button2"){      button2 = true;      alert("test1");    }    if (postmessage == "test2"){      button3 = true;      alert("test2");    }    if (postmessage == "test3"){      button4 = true;      alert("test3");    }	  }    function next(){    if(button1 == true || button2 == true){      window.location = "test/test1.html";    }    else{      alert("choose side");    }  }
<button id="mybtn" value="myvalue" onclick="myfunction()">try it</button>    <p id="demo"></p>  <button id="next1" value="gonext" onclick="next()">next</button>


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -