Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2011, 02:12 PM   PM User | #1
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 283
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
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..
paddyfields is offline   Reply With Quote
Old 02-06-2011, 02:29 PM   PM User | #2
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 283
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
onBlur() !
paddyfields is offline   Reply With Quote
Old 02-06-2011, 04:26 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,705
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 02-06-2011, 07:42 PM   PM User | #4
leapinglemur55
New Coder

 
Join Date: Jan 2011
Location: California
Posts: 20
Thanks: 0
Thanked 5 Times in 5 Posts
leapinglemur55 is an unknown quantity at this point
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.
leapinglemur55 is offline   Reply With Quote
Old 02-06-2011, 11:14 PM   PM User | #5
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,705
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:38 AM.


Advertisement
Log in to turn off these ads.