window.location not working

  • delhipro
  • Novice
  • Novice
  • delhipro
  • Posts: 28
  • Loc: india

Post 3+ Months Ago

I have the following html page, but the window.location command is not working, while the next line alert("this is ms office") works perfectly, why window.location is not moving me to abc.html, if the user enters mso in the text box and clicks submit.

HTML Code: [ Select ]
<html>
<head>
<script type="text/javascript">
 
function passcode()
{
course=document.serialenter.course.value;
 
if (course=="mso")
{
window.location = "abc.html";
alert("this is ms office");
}
else
{
alert("You have entered a wrong serial number");
}  
 
}
 
//-->>
</script>
 
 
 
</HEAD>
<BODY>
<form name=serialenter>
<table width=100% border=0>
<tr width=100% align=center><TD colspan=3>
Please fill in the course code:
<input type=text size=3 maxlength=3 name=course>
<input type=submit value="Submit" name=submit onclick=passcode()>
 
</td></tr>
 
</table>
</form>
 
</body>
</html>
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. function passcode()
  6. {
  7. course=document.serialenter.course.value;
  8.  
  9. if (course=="mso")
  10. {
  11. window.location = "abc.html";
  12. alert("this is ms office");
  13. }
  14. else
  15. {
  16. alert("You have entered a wrong serial number");
  17. }  
  18.  
  19. }
  20.  
  21. //-->>
  22. </script>
  23.  
  24.  
  25.  
  26. </HEAD>
  27. <BODY>
  28. <form name=serialenter>
  29. <table width=100% border=0>
  30. <tr width=100% align=center><TD colspan=3>
  31. Please fill in the course code:
  32. <input type=text size=3 maxlength=3 name=course>
  33. <input type=submit value="Submit" name=submit onclick=passcode()>
  34.  
  35. </td></tr>
  36.  
  37. </table>
  38. </form>
  39.  
  40. </body>
  41. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

Your HTML isn't well-formed. All tag attribute values must be enclosed in double quotes, like so:
HTML Code: [ Select ]
<input type="submit" value="Submit" name="submit" onclick="passcode();" />

Also, <input> tags are self-closing; you have not specified them as such.

Check all of your tags, fix them up, then run it again.
  • hgun77
  • Graduate
  • Graduate
  • User avatar
  • Posts: 164
  • Loc: Malaysia

Post 3+ Months Ago

definately your script cant get
JAVASCRIPT Code: [ Select ]
course=document.serialenter.course.value;
 
  1. course=document.serialenter.course.value;
  2.  


try to use light library like jQuery. so you can get a value of a input by
JAVASCRIPT Code: [ Select ]
$('#someid').val();
 
  1. $('#someid').val();
  2.  

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 115 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.