0

How to clear defaulttext in textbox by clicking on it and bring back defaut text in textbox when clicking outside of same textbox.

2
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by pratham3090
0

On this forum, you'll find that you need to put a little effort in trying before getting help. Since I already had a code snippet, I'm providing it here for you. However, I would suggest that you do some research on your own. The following is a very simple example on how to use the onfocus and onblur events. by no means is this a final solution for your problem. It is only meant to be used as a demonstration. If you are new to asp.net, I would suggest that you go back and first learn HTML, CSS, and JavaScript really well before you continue with your asp.net development. It is going to make it easier for you as you get deeper into asp.net development.

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<script>
    function checkFocus(textValue) {
        if (textValue === "username") {
            document.getElementById("usernameenter").value = "";
        }
        else {
            document.getElementById("passwordenter").value = "";
        }
    }

    function doBlur(textValue) {
        if (document.getElementById("usernameenter").value === "") {
            document.getElementById("usernameenter").value = "username";
        }
        if (document.getElementById("passwordenter").value === "") {
            document.getElementById("passwordenter").value = "password";
        }
    }
</script>
<body>
Username: <input type="text"  name="username" value="username" onfocus="checkFocus(this.value)" onblur="doBlur(this.value)" /><br />
Password: <input type="password" name="password" value="Password" onfocus="checkFocus(this.value)" onblur="doBlur(this.value)" /><br />
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.