
Step 2:
- <input id="txtname" type="text" value="Enter your name here" onblur="ShowName()" />
- <input id="txtage" type="text" value="Enter your age here" onblur="ShowAge()" /></td><input id="txtname" type="text" value="Enter your name here" onblur="ShowName()" />
- <input id="txtage" type="text" value="Enter your age here" onblur="ShowAge()" /></td>

Here we call two functions ShowName() and ShowAge(). These functions are useful as they check the value of the TextBox and if the TextBox has a value it will set it as TextBox value otherwise it will set the default value ("Enter your name Here" or "Enter your age here").
Step 3: Now we declare the JavaScript functions ShowName() and ShowAge():
- <script language="JavaScript" type="text/javascript" >
- function ShowName() {
- var n = document.getElementById('txtname').value;
- if (n == "") {
- document.getElementById('txtname').value = "Enter your name here";
- }
- }
- function ShowAge() {
- var a = document.getElementById('txtage').value;
- if (a == "") {
- document.getElementById('txtage').value = "Enter your age Here ";
- }
- }
- </script>


Rushal AroraPosted Jun 28, 2012, 6:16 AM
how can i apply watermark on textbox of password field?
manoj prabakaranPosted Jun 8, 2012, 7:53 AM
it is not working can u help me. thanks
surender bhyanPosted Jun 23, 2011, 1:01 PM
But when i click in the input field old text remains, How i empty the field...thanks