How to create a dll in dotnet

To get something you never had, you have to do something you never did-Bimal Patel

Monday, November 15, 2010

Developing a Masked Textbox



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

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








2 comments:

  1. but will dis value be passed to the database after execution

    ReplyDelete
  2. ya this can be passed with out problem.
    just check like this
    if(txtUsername.text!="Enter Your Name")
    {

    }

    ReplyDelete