javascript - Having a code on website that works with alert but doesn't link to another website when the if condition is met -


i having trouble html/javascript document have copied code below.

i have created input textbox , button runs function check(). code executes using alerts when substitute alert link direct user webpage when condition met.

in example condition 40.

i have external stylesheet linked document , external javascript script attached well.

thanks...

edit - might easier have made simple file code want excecuted below

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <script type="text/javascript"> function check (){     var codeentered = document.getelementbyid("promocode").value;       if (codeentered==40)   {  //alert ("work")  window.location.assign = "http://www.w3schools.com";   }   else if (codeentered == "")   {   alert ("please enter promotional code.")     }   else   {   alert ("promotional code incorrect")   } } </script>  <body> <form id="form3" name="form3" method="post" action="">       <label for="promocode">promotional code:</label>       <input type="text" name="promocode" id="promocode" />     </form>     <p></p>  <p>&nbsp;</p> <form id="form1" name="form1" method="post" action="">   <input type="submit" name="submit" id="submit" value="submit code" onclick="check()" /> </form> </body> </html> 

the form submit button in, being posted before page has chance redirect.

given you're not posting data, don't need either of forms. if want surround elements in order add style, use div instead.

note window.location.assign has been changed window.location also.

<script type="text/javascript"> function check(){   var codeentered = document.getelementbyid("promocode").value;   if (codeentered==40)   {     window.location = "http://www.w3schools.com";   }   else if(codeentered == "")   {     alert("please enter promotional code.")     }   else   {     alert("promotional code incorrect")   } } </script>  <body>       <label for="promocode">promotional code:</label>       <input type="text" name="promocode" id="promocode" />    <p>&nbsp;</p>    <button type="button" value="submit code" onclick="check()" >submit code</button>  </body> </html> 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -