JavaScript Alert box not working before redirecting the user









up vote
1
down vote

favorite












<html>
<head>
</head>
<body>

<script>
function myFun()

var correct_way = /^[A-Za-z0-9]+$/;

var a = document.getElementById("User_Name").value;

if(a=="")
document.getElementById("Message").innerHTML="Please enter a username.";
return false;

if(a.length<5)
document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
return false;

if(a.match(correct_way))
alert.("Sucessful Login, welcome to BREAKOUT!");
document.location.href = "test1.html";
else
document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
return false;


return true;

</script>

<form action="test1.html" onsubmit="return myFun()">
<input type="text" id="User_Name" value=""></input>
<br></br>
<span id="Message"> </span>
<br></br>
<input type="submit" value="Submit"></input>
</form>
</body>

</html>


Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?










share|improve this question



























    up vote
    1
    down vote

    favorite












    <html>
    <head>
    </head>
    <body>

    <script>
    function myFun()

    var correct_way = /^[A-Za-z0-9]+$/;

    var a = document.getElementById("User_Name").value;

    if(a=="")
    document.getElementById("Message").innerHTML="Please enter a username.";
    return false;

    if(a.length<5)
    document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
    return false;

    if(a.match(correct_way))
    alert.("Sucessful Login, welcome to BREAKOUT!");
    document.location.href = "test1.html";
    else
    document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
    return false;


    return true;

    </script>

    <form action="test1.html" onsubmit="return myFun()">
    <input type="text" id="User_Name" value=""></input>
    <br></br>
    <span id="Message"> </span>
    <br></br>
    <input type="submit" value="Submit"></input>
    </form>
    </body>

    </html>


    Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      <html>
      <head>
      </head>
      <body>

      <script>
      function myFun()

      var correct_way = /^[A-Za-z0-9]+$/;

      var a = document.getElementById("User_Name").value;

      if(a=="")
      document.getElementById("Message").innerHTML="Please enter a username.";
      return false;

      if(a.length<5)
      document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
      return false;

      if(a.match(correct_way))
      alert.("Sucessful Login, welcome to BREAKOUT!");
      document.location.href = "test1.html";
      else
      document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
      return false;


      return true;

      </script>

      <form action="test1.html" onsubmit="return myFun()">
      <input type="text" id="User_Name" value=""></input>
      <br></br>
      <span id="Message"> </span>
      <br></br>
      <input type="submit" value="Submit"></input>
      </form>
      </body>

      </html>


      Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?










      share|improve this question















      <html>
      <head>
      </head>
      <body>

      <script>
      function myFun()

      var correct_way = /^[A-Za-z0-9]+$/;

      var a = document.getElementById("User_Name").value;

      if(a=="")
      document.getElementById("Message").innerHTML="Please enter a username.";
      return false;

      if(a.length<5)
      document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
      return false;

      if(a.match(correct_way))
      alert.("Sucessful Login, welcome to BREAKOUT!");
      document.location.href = "test1.html";
      else
      document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
      return false;


      return true;

      </script>

      <form action="test1.html" onsubmit="return myFun()">
      <input type="text" id="User_Name" value=""></input>
      <br></br>
      <span id="Message"> </span>
      <br></br>
      <input type="submit" value="Submit"></input>
      </form>
      </body>

      </html>


      Hello, I have created a username validation code. The validation does work however, the user is not redirected to the 'test1.html' document. They are both in the same folder. How do i make it redirect after the validation is checked?







      javascript html html5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 15:19

























      asked Nov 10 at 14:59









      Rolls_Reus_0wner

      114




      114






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You should return true at the end of function myFun.



          HTML



          <form action="test1.html" onsubmit="return myFun()">
          <input type="text" id="User_Name" value="" />
          <span id="Message"> </span>
          <input type="submit" value="Submit" />
          </form>


          Updated code



          function myFun()
          var correct_way = /^[A-Za-z0-9]+$/;

          var a = document.getElementById("User_Name").value;

          if(a=="")
          document.getElementById("Message").innerHTML="Please enter a username.";
          return false;

          if(a.length<5)
          document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
          return false;

          if(a.match(correct_way))
          alert("Sucessful Login, welcome to BREAKOUT!");


          else
          document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
          return false;


          return true;



          jsFiddle demo - http://jsfiddle.net/h67q09mp/






          share|improve this answer






















          • thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
            – Rolls_Reus_0wner
            Nov 10 at 15:09











          • Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
            – front_end_dev
            Nov 10 at 15:15










          • So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
            – Rolls_Reus_0wner
            Nov 10 at 15:22










          • That's correct.
            – front_end_dev
            Nov 10 at 15:23










          • It does not appear!
            – Rolls_Reus_0wner
            Nov 10 at 15:27










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240179%2fjavascript-alert-box-not-working-before-redirecting-the-user%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          You should return true at the end of function myFun.



          HTML



          <form action="test1.html" onsubmit="return myFun()">
          <input type="text" id="User_Name" value="" />
          <span id="Message"> </span>
          <input type="submit" value="Submit" />
          </form>


          Updated code



          function myFun()
          var correct_way = /^[A-Za-z0-9]+$/;

          var a = document.getElementById("User_Name").value;

          if(a=="")
          document.getElementById("Message").innerHTML="Please enter a username.";
          return false;

          if(a.length<5)
          document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
          return false;

          if(a.match(correct_way))
          alert("Sucessful Login, welcome to BREAKOUT!");


          else
          document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
          return false;


          return true;



          jsFiddle demo - http://jsfiddle.net/h67q09mp/






          share|improve this answer






















          • thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
            – Rolls_Reus_0wner
            Nov 10 at 15:09











          • Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
            – front_end_dev
            Nov 10 at 15:15










          • So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
            – Rolls_Reus_0wner
            Nov 10 at 15:22










          • That's correct.
            – front_end_dev
            Nov 10 at 15:23










          • It does not appear!
            – Rolls_Reus_0wner
            Nov 10 at 15:27














          up vote
          1
          down vote













          You should return true at the end of function myFun.



          HTML



          <form action="test1.html" onsubmit="return myFun()">
          <input type="text" id="User_Name" value="" />
          <span id="Message"> </span>
          <input type="submit" value="Submit" />
          </form>


          Updated code



          function myFun()
          var correct_way = /^[A-Za-z0-9]+$/;

          var a = document.getElementById("User_Name").value;

          if(a=="")
          document.getElementById("Message").innerHTML="Please enter a username.";
          return false;

          if(a.length<5)
          document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
          return false;

          if(a.match(correct_way))
          alert("Sucessful Login, welcome to BREAKOUT!");


          else
          document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
          return false;


          return true;



          jsFiddle demo - http://jsfiddle.net/h67q09mp/






          share|improve this answer






















          • thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
            – Rolls_Reus_0wner
            Nov 10 at 15:09











          • Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
            – front_end_dev
            Nov 10 at 15:15










          • So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
            – Rolls_Reus_0wner
            Nov 10 at 15:22










          • That's correct.
            – front_end_dev
            Nov 10 at 15:23










          • It does not appear!
            – Rolls_Reus_0wner
            Nov 10 at 15:27












          up vote
          1
          down vote










          up vote
          1
          down vote









          You should return true at the end of function myFun.



          HTML



          <form action="test1.html" onsubmit="return myFun()">
          <input type="text" id="User_Name" value="" />
          <span id="Message"> </span>
          <input type="submit" value="Submit" />
          </form>


          Updated code



          function myFun()
          var correct_way = /^[A-Za-z0-9]+$/;

          var a = document.getElementById("User_Name").value;

          if(a=="")
          document.getElementById("Message").innerHTML="Please enter a username.";
          return false;

          if(a.length<5)
          document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
          return false;

          if(a.match(correct_way))
          alert("Sucessful Login, welcome to BREAKOUT!");


          else
          document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
          return false;


          return true;



          jsFiddle demo - http://jsfiddle.net/h67q09mp/






          share|improve this answer














          You should return true at the end of function myFun.



          HTML



          <form action="test1.html" onsubmit="return myFun()">
          <input type="text" id="User_Name" value="" />
          <span id="Message"> </span>
          <input type="submit" value="Submit" />
          </form>


          Updated code



          function myFun()
          var correct_way = /^[A-Za-z0-9]+$/;

          var a = document.getElementById("User_Name").value;

          if(a=="")
          document.getElementById("Message").innerHTML="Please enter a username.";
          return false;

          if(a.length<5)
          document.getElementById("Message").innerHTML="Please enter a username with 5 or more characters";
          return false;

          if(a.match(correct_way))
          alert("Sucessful Login, welcome to BREAKOUT!");


          else
          document.getElementById("Message").innerHTML="Please enter a username with only letters and integers";
          return false;


          return true;



          jsFiddle demo - http://jsfiddle.net/h67q09mp/







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 15:36

























          answered Nov 10 at 15:02









          front_end_dev

          1,310411




          1,310411











          • thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
            – Rolls_Reus_0wner
            Nov 10 at 15:09











          • Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
            – front_end_dev
            Nov 10 at 15:15










          • So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
            – Rolls_Reus_0wner
            Nov 10 at 15:22










          • That's correct.
            – front_end_dev
            Nov 10 at 15:23










          • It does not appear!
            – Rolls_Reus_0wner
            Nov 10 at 15:27
















          • thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
            – Rolls_Reus_0wner
            Nov 10 at 15:09











          • Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
            – front_end_dev
            Nov 10 at 15:15










          • So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
            – Rolls_Reus_0wner
            Nov 10 at 15:22










          • That's correct.
            – front_end_dev
            Nov 10 at 15:23










          • It does not appear!
            – Rolls_Reus_0wner
            Nov 10 at 15:27















          thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
          – Rolls_Reus_0wner
          Nov 10 at 15:09





          thanks! one more thing. I would like to put alerts instead of the document Get element by id messages. I tried putting alert.("Sucessful Login, welcome to BREAKOUT!"); however, the alert does not appear.
          – Rolls_Reus_0wner
          Nov 10 at 15:09













          Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
          – front_end_dev
          Nov 10 at 15:15




          Where did you put the alert. Replace this line document.location.href = "test1.html"; with alert box. I have created an jsFiddle - jsfiddle.net/u75w2r6s
          – front_end_dev
          Nov 10 at 15:15












          So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
          – Rolls_Reus_0wner
          Nov 10 at 15:22




          So, I have put the alert in the if(a.match(correct_way)) statement. Basically, when the username is validated a alert box should say "Successful Login, welcome to BREAKOUT!" and redirect the user to test1.html
          – Rolls_Reus_0wner
          Nov 10 at 15:22












          That's correct.
          – front_end_dev
          Nov 10 at 15:23




          That's correct.
          – front_end_dev
          Nov 10 at 15:23












          It does not appear!
          – Rolls_Reus_0wner
          Nov 10 at 15:27




          It does not appear!
          – Rolls_Reus_0wner
          Nov 10 at 15:27

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240179%2fjavascript-alert-box-not-working-before-redirecting-the-user%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto