Jump to content

[SOLVED] OnClick OnBlur HELP!!!


DeanWhitehouse

Recommended Posts

This is my form

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" >
To : <input type="text" value="<?php echo $to; ?>" name="to" size="30" onClick="this.value=''" title="Enter The Recipients Email Address">
<br ><br >
From : <input type="text" value="<?php echo $from; ?>" name="from" size="30" onClick="this.value=''" title="Enter Your Email Or Name">
<br><br>
Subject : <input type="text" value="<?php echo $subject; ?>"  name="subject" size="30" onClick="this.value=''" title="Enter The Email Subject">
<br ><br >
Message:<br >
<textarea title="Enter Your Message" name="message" onClick="this.value=''" rows="10" cols="100"><?php echo $message; ?></textarea>
<br>
<input type="submit" name="send" value="Send" title="Send The Email" size="30">
</form>

the problem i am having is that, when i enter details into the form and then click on it, it emptys, how can i fix this and i did have an OnBlur so that when they click out of the box it re-enters the value, how can i get it to only do this if they haven't entered anything?

Link to comment
Share on other sites

On focus, check to see if the value of the input/text area is the default value. If it is, clear it, if its not, do nothing. On blur, check to see if the value is empty. If it is, then replace it with the default value.

Link to comment
Share on other sites

This code will only clear the box if the default text is still there. You obviously have to switch the two "default"'s with the default value that you want the text box to have.

<input type="Text" value="default" onFocus="if(this.value='default')this.value=''">

Link to comment
Share on other sites

  • 4 weeks later...

I have this code

                    <input name="uname" type="text" class="Field1" id="uname" value="Username" onFocus=
				"
				if(this.value = 'Username')
				{
				this.value = '';
				}
				else
				{
				alert('cake');
				}
				" 
			 	onblur=
				"
				if(this.value = ' ')
				{
				this.value = 'Username';
				}
				"
				/>

 

but this inserts Username into the field, even if you enter something, any help?

Link to comment
Share on other sites

  • 2 weeks later...

The problem is you need to add another equals sign to the onblur 'if' statement like this:


<input name="uname" type="text" class="Field1" id="uname" value="Username" onFocus=
				"
				if(this.value = 'Username')
				{
				this.value = '';
				}
				else
				{
				alert('cake');
				}
				" 
			 	onblur=
				"
				if(this.value == ' ')
				{
				this.value = 'Username';
				}
				"
				/>

 

That should work for you. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.