开发者

Autoset textbox values with jQuery

I have the following code:

this.urlSet = function(){
    $("#url").keyup(function(){
  开发者_JAVA百科      $("#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!


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));
    });
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜