We can clear the contents of a textbox on clicking it using javascript. Create a textbox with id attribute, for example say “username”
1 | <input type="text" id="username" value="Enter username" onFocus="clearall()"/> |
Create a javascript function that will be called when the textbox is focused,
1 2 3 4 5 6 7 8 9 10 11 | <script type="text/javascript"> function clearall() { var txt=document.getElementById('username'); //alert(txt.value); //Check for the default text and clear it when the user clicks over. if(txt.value == "Enter username"){ txt.value=''; } } </script> |
If you want to clear the textbox without checking the text, simply use the following without any of the above code.
1 | <input type="text" id="username" value="Enter username" onFocus="this.value=''"/> |

