SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "Onblur" problem,please help

    Code:
    <html>
    
    <head>
    
    
    <title>You must login first before you order any book</title>
    
    <script language=Javascript type="text/javascript">
    
    function checkname(x)
    {
    
    if(x.value==""){
    window.alert("you must enter a username")
    x.focus()
    
    }
    }
    
    
    function checkpass(y)
    {
    
    if(y.value==""){
    window.alert("you must enter a password")
    y.focus()
    
    }
    }
    </script>
    
    </head>
    <body>
    
    
    
    
    
    
    <a href="homepage.html"> Back To Home</a>
    
    
    <form  name=reg method="POST" action="login.php">
    	<p>&nbsp;</p>
    	<p><b><font size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	 You must login first before you order any book</font></b></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    	Username
    	<input type="text" name="username" size="20" onblur="checkname(this)"></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    Password&nbsp;<input type="text" name="password" size="20" onblur="checkpass(this)"></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Reset" name="B2"></p>
    </form>
    
    </body>
    
    </html>
    my problem is once the error message pop up,unable to stop it ,it will loop foever.How to edit this code?

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cty View Post
    Code:
    <html>
    
    <head>
    
    
    <title>You must login first before you order any book</title>
    
    <script language=Javascript type="text/javascript">
    
    function checkname(x)
    {
    
    if(x.value==""){
    window.alert("you must enter a username")
    x.focus()
    
    }
    }
    
    
    function checkpass(y)
    {
    
    if(y.value==""){
    window.alert("you must enter a password")
    y.focus()
    
    }
    }
    </script>
    
    </head>
    <body>
    
    
    
    
    
    
    <a href="homepage.html"> Back To Home</a>
    
    
    <form  name=reg method="POST" action="login.php">
    	<p>&nbsp;</p>
    	<p><b><font size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	 You must login first before you order any book</font></b></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    	Username
    	<input type="text" name="username" size="20" onblur="checkname(this)"></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    Password&nbsp;<input type="text" name="password" size="20" onblur="checkpass(this)"></p>
    	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Reset" name="B2"></p>
    </form>
    
    </body>
    
    </html>
    my problem is once the error message pop up,unable to stop it ,it will loop foever.How to edit this code?
    Alerting on blur is a common beginners' mistake and is not good practice. The infinite loop occurs because clicking the OK button blurs the field again. If you must alert on blur, either let the user refocus the field (assuming that they weren't trying to abandon the form when the alert was triggered) or cancel the onblur handler:

    x.onblur=null;
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •