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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.