hmvrulz
01-11-2008, 12:47 PM
<input type="text" name="name" size="20" maxlength="30" value="Name"/>
on clicking the above field how can i make the value Name vanish ??
on clicking the above field how can i make the value Name vanish ??
|
||||
Making a Initial Text Value Vanish one selectedhmvrulz 01-11-2008, 12:47 PM <input type="text" name="name" size="20" maxlength="30" value="Name"/> on clicking the above field how can i make the value Name vanish ?? VIPStephan 01-11-2008, 01:27 PM With JavaScript only: <input type="text" name="name" size="20" maxlength="30" value="Name" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" /> hmvrulz 01-11-2008, 03:35 PM thanx mate... Bambam007 10-04-2008, 01:57 AM Thank you Thank you Thank you You are the best. Nice, clean code too - works with other events perfectly =] Bambam007 10-04-2008, 02:04 AM Just out of interest... Say there were multiple text inputs with different values. Would you need a set of the code for each one or is the a var option for that, like 'get the value'? Bambam007 10-04-2008, 02:42 AM oops replied in the wrong thread - my bad ill repost in the correct one =[ itsallkizza 12-31-2008, 02:33 PM This code is a bit better because they can now enter in as input whatever the default text is (this can come in handy if you're giving a default date or first name or whatever): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Example</title> <style type="text/css"> </style> <script type="text/javascript"> // <![CDATA[ function clearOnce(input_element) { if (!input_element.alreadyCleared) { input_element.value = ""; input_element.alreadyCleared = true; } } // ]]> </script> </head> <body> <form onsubmit="return false"> <input type="text" onfocus="clearOnce(this)" value="type stuff here" /><br /> <input type="text" onfocus="clearOnce(this)" value="and here" /> </form> </body> </html> abduraooft 12-31-2008, 02:58 PM This code is a bit better because they can now enter in as input whatever the default text is (this can come in handy if you're giving a default date or first name or whatever): but that won't retain the original text when the user deletes everything s/he typed. itsallkizza 12-31-2008, 04:46 PM I wasn't commenting on the given onblur - that one was fine, although modularizing it into a central function would be preferable. The onblur function to me seems a bit more case-by-case-ish anyway. In most of the forms I create, I wouldn't want the default value to pop back in if the user deleted the input text. Whether you want it to do that or not is up to the developer. lozbenson 11-01-2009, 02:11 PM Thanks, Thats great!!! |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum