Usually in some of the registartion pages we can see a text in textbox saying enterusername,enteremailid etc
and when we try to focus on it the text disappears as below
Enter your name:
procedure
1)write a function named intialize as below
and call in it onload event of body
and call in it onload event of body
function initialize() {
var name = document.getElementById('txtUsername');
name.value = 'Enter Your Name';
name.style.color = 'DarkGray';
}
2)write 2 more functions named chTextin() and chTextout() as below
function chTextin() { var txt = document.getElementById('txtUsername'); if (txt.value == 'Enter Your Name') { txt.value = ''; txt.style.color = ''; } }
function chTextout() { var txt = document.getElementById('txtUsername'); if (txt.value == '') { txt.value = 'Enter Your Name'; txt.style.color = 'DarkGray'; } }
3)Now take a html and onfocus and blur events as below
<input type='text' id='txtUsername' onfocus="chTextin();" onblur="chTextout();"/>
the final code will be like this
<html> <head> <script type="text/javascript"> function chTextin() { var txt = document.getElementById('txtUsername'); if (txt.value == 'Enter Your Name') { txt.value = ''; txt.style.color = ''; } } function chTextout() { var txt = document.getElementById('txtUsername'); if (txt.value == '') { txt.value = 'Enter Your Name'; txt.style.color = 'DarkGray'; } } function initialize() { var name = document.getElementById('txtUsername'); name.value = 'Enter Your Name'; name.style.color = 'DarkGray'; } </script> </head> </head> <body onload="initialize();"> Enter your name: <input type='text' id='txtUsername' onfocus="chTextin();"
onblur="chTextout();"/> </body> </html>
----------------------------------------------------
Now copy paste the above code it works like a charm
but will dis value be passed to the database after execution
ReplyDeleteya this can be passed with out problem.
ReplyDeletejust check like this
if(txtUsername.text!="Enter Your Name")
{
}