简体   繁体   中英

How to redirect page based on user input?

Using JavaScript, I am trying to set up a page redirect based on user input from a text box. When I fill out the text box, each if condition is met but the page is not redirecting.

<script type="text/javascript"> 
 
  function validateTextBox() { 
  
    var box = document.getElementById("width")
    var box2 = document.getElementById("height")
    var box3 = document.getElementById("length")
  
    if (box.value < 25 && box2.value < 25 && box3.value < 25) {
      window.location.href = "jointext.html";
    }                               
  }                                
</script>
     
</head>
    
<body>

<form id="theform" action="" method="post" onsubmit="validateTextBox()">
  <h3> What do I need </h3>
  <div class="row">
    <label for ="width"> Width Of Room in Metres </label> <br>
    <input type="text" id="width" name=""> <br><br>
  </div>

I have no idea why am I on the right lines?

I am fairly new in my learning so any advice would be great. Is this the way to go about this and if so what have I done wrong. Thanks all

Try using "onsubmit" instead of "onSubmit".

New Answer Try using action="URL" instead of action="" for redirection. If you wish to use it in function call remove action="".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM