Jump to content

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
https://forums.phpfreaks.com/topic/110652-solved-onclick-onblur-help/
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?

  • 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. :)

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.