"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, July 6, 2010

pre-text on texbox or watermark on textbox without using ajax

Hi friends,
pre-text in texbox is very much common on web pages. i seen so many web pages using Ajax and jquery for this stuff.But i have simple one where i'm using only the client side event of the textbox. onFocus, onBlur.

DEMO



Description
i'm passing the pretext on the time i initialize the txtbox and on onfocus event i'm i make the value to empty and onBlur event i check the value if it is null i make the value to my pre-text :). it's done by a simple if else statement
code 

 <td ><input name="Firstname" type="text" class="text" id="email" onFocus="if (this.value=='Firstname'){this.value='';};return false;" onBlur="if (this.value==''){this.value='Firstname';return false;}" value="Firstname" size="15"></td>

JavaScript: The Good PartsJavaScript: The Definitive GuideObject-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications and libraries 
 


No comments: