开发者

Autoset textbox values with jQuery

开发者 https://www.devze.com 2023-02-22 08:56 出处:网络
I have the following code: this.urlSet = function(){ $(\"#url\").keyup(function(){ 开发者_JAVA百科$(\"#firstpath\").val() = $(\"#url\").val().substring(0,8);

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

精彩评论

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

关注公众号