DeanWhitehouse Posted June 17, 2008 Share Posted June 17, 2008 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? Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 Can you re-read your question and re-state it? You used 'how can' twice, which made it a little confusing. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted June 18, 2008 Author Share Posted June 18, 2008 How can i have it clear the field when you click on it, but only if you havent entered anything? and How can i have it so that when you click out of the box it re-enters the default value if you havent entered anything?? Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted June 18, 2008 Author Share Posted June 18, 2008 Ok, i don't really know JS , can anyone give me an example code? Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 18, 2008 Share Posted June 18, 2008 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=''"> Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 Sorry, I'm more than happy to help with code people are having troubles with, but writing code is my day job, and I get paid at my day job! Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted July 12, 2008 Author Share Posted July 12, 2008 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? Quote Link to comment Share on other sites More sharing options...
vtowntim Posted July 26, 2008 Share Posted July 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.