views:

45

answers:

1

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

https://in.edit.yahoo.com/registration?intl=in&done=http%3A%2F%2Fmail.yahoo.com&src=ym&last=&partner=yahoo%5Fdefault&domain=&yahooid=&ipmsg=in

+1  A: 

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