Chris Bornhoft
Chris Bornhoft

Reputation: 4301

Autoset textbox values with jQuery

I have the following code:

this.urlSet = function(){
    $("#url").keyup(function(){
        $("#firstpath").val() = $("#url").val().substring(0,8);
        $("#secndpath").val() = $("#url").val().substring(0,8);
        $("#thirdpath").val() = $("#url").val().substring(0,8);
    });
};

I'm trying to get the three textboxes named "xxxpath" to fill with the first 8 characters of the url textbox as the user is typing. However, with the code in this state, nothing happens. Anyone have a quick idea where I'm going wrong?

Thanks!

Upvotes: 1

Views: 247

Answers (1)

bluish
bluish

Reputation: 27410

You need to use val(value_to_set) function, because val() it's only to get the value:

this.urlSet = function(){
    $("#url").keyup(function(){
        $("#firstpath").val($("#url").val().substring(0,8));
        $("#secndpath").val($("#url").val().substring(0,8));
        $("#thirdpath").val($("#url").val().substring(0,8));
    });
};

Upvotes: 1

Related Questions