I want to do the same functionality for first name Field and Surname field in the registration page of yahoo. When i clicks on textbox. Default text dissapears. And when i loses the focus from same textbox the default text appears again. Here is the yahoo registration page. How can i do this. I want to do xactly same functionality. Can you plz suggest me idea, how to do this
Asked
Active
Viewed 244 times
1
-
1Duplicate of http://stackoverflow.com/questions/1911301/javascript-watermarks-for-textboxes – jball Dec 22 '09 at 20:28
-
2It may help you to know that this is called javascript "watermarks". – DOK Dec 22 '09 at 20:30
-
@jball Does this work for asp controls as well – Shantanu Gupta Dec 22 '09 at 20:34
-
shantanu you can include javascript inside of asp.net – JonH Dec 22 '09 at 20:46
-
Shantanu is what I posted not enough information? I can elaborate more information if need be ? – JonH Dec 23 '09 at 16:22
1 Answers
1
If you are using AJAX you can use the TextBoxWatermark which is an asp.net ajax extender. This is probably the easiest way to do it. If you are not using ajax, you could use JS.
If you want you can do this in jquery:
$(document).ready(function() {
var w = "Search...";
if($("#txtS").val() == "") {
$("#txtS").val(watermark);
}
$("#txtS").focus(function() {
if(this.value == watermark) {
this.value="";
}
}).blur(function() {
if(this.value=="") {
this.value = watermark;
}});
});
The first function sets the watermark. The focus function checks if you're setting the focus to what the watermark originally is. If it is it sets the textbox to empty. When you leave the textbox (blur) if you did not type anything in it sets it back to the watermark. Most examples can be found on codedigest or the jquery site.

JonH
- 32,732
- 12
- 87
- 145