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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts

    onlick and onchange events?

    Hello.

    I'm new to JavaScript to any help in understanding would be great. For an html form, i'm am trying to have it so when a user clicks on the 'email' input box then a div element next to it displays "please make sure it's correct", and when they click out of the box (ie, to the next field), the message disappears again.

    I have managed to make it appear using this;

    Code:
    function displaymessage()
    {
    document.getElementById("message").innerHTML="please make sure your email address isn't fake.. you dick";
    }
    
    <input class="textbox" name="email" onclick="displaymessage()"<input type='<p id="message"></p>
    BUT, how do i make it disappear when the user clicks out.. is it onchange()?.. if so, how.

    many thanks!!
    Last edited by paddyfields; 02-06-2011 at 02:29 PM.

  • #2
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    onBlur() !

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    Quote Originally Posted by paddyfields View Post
    onBlur() !
    As a matter of fact you shouldn’t use onclick there but rather onfocus() (and onblur() as counterpart).

  • #4
    New Coder
    Join Date
    Jan 2011
    Location
    California
    Posts
    20
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Code:
    function displaymessage()
    {
    document.getElementById("message").innerHTML="please make sure your email address isn't fake.. you dick";
    }
    function hidemessage()
    {
    document.getElementById("message").innerHTML="";
    }
    
    <input type="text" class="textbox" name="email" onFocus="displaymessage()" onBlur="hidemessage()" /><p id="message"></p>
    Try this. You need to use onFocus and onBlur instead of onClick.

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,662
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    Quote Originally Posted by leapinglemur55 View Post
    Code:
    function displaymessage()
    {
    document.getElementById("message").innerHTML="please make sure your email address isn't fake.. you dick";
    }
    function hidemessage()
    {
    document.getElementById("message").innerHTML="";
    }
    
    <input type="text" class="textbox" name="email" onFocus="displaymessage()" onBlur="hidemessage()" /><p id="message"></p>
    Try this. You need to use onFocus and onBlur instead of onClick.
    Since you’re apparently writing XHTML I just wanna add for the records that everything must be lowercase, i. e. onblur, not onBlur.


  •  

    Posting Permissions

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