Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    on error show/hide div problem

    Hi,

    I have a login screen if the user doesn't enter a username, I want a box just underneath the page title to display an error message for a few seconds and then return focus to the username field. This is how my boss wants it.

    I am having a difficult time trying to do this.

    I have attached my code. If someone could help me out that would be great.

    Thanks.
    Attached Files Attached Files

  • #2
    New Coder
    Join Date
    Oct 2012
    Location
    Basement
    Posts
    88
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Please copy/paste your codes here. thanks.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try this example:-

    Code:
    <html>
    <head>
    <body>
    
    Enter your username <input type = "text" id = "uname">
    <br>
    <span id = "message" style=color:"red"; style = "visibility:hidden">You must fill in your user name</span>
    <br>
    <input type = "button" value = "Submit" onclick = "checkun()">
    
    <script type = "text/javascript">
    function checkun() {
    var u = document.getElementById("uname").value;
    if (u.length < 3) {
    document.getElementById("message").style.visibility = "visible";
    setTimeout(clearit,4000);  // show for 4 seconds
    }
    }
    
    function clearit() {
    document.getElementById("message").style.visibility = "hidden";
    document.getElementById("uname").focus();
    }
    
    </script>
    
    </body>
    </html>

    Quizmaster: Which southern European country was ruled by Antonio Salazar from 1932 to 1968?
    Contestant: Russia.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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