Geeth
Geeth

Reputation: 5343

Label behind the textbox

I am using the following sample to display text in the background of the textbox. It is working fine too. http://attardi.org/labels/

Problem:

I want to increase the text box with. The box looks like it expanded but while typing the actual size is not expanded. I want to type text till 600px.

Geetha.

Upvotes: 2

Views: 412

Answers (1)

Gabriel
Gabriel

Reputation: 18780

$(".input :input").keypress(function(){
    var o = $(this); 
    var s = $("<span></span>").html(o.val()).addClass('placeholder').css('left', '-9999px'); 
    if (o.outerWidth() < 600) {
        o.parent().append(s); 
        if (s.outerWidth() > o.outerWidth()){
            o.css("width", s.outerWidth()); 
        }
        $("span.placeholder").remove();
    }
});

I tested this and it seems to work pretty good. not bad for 7 minutes of code/test/burn.

Upvotes: 1

Related Questions