开发者

add textbox dynamicaly using dropdown with jQuery

开发者 https://www.devze.com 2023-02-10 14:19 出处:网络
Dynamically add textbox using jquery from the link above i want something like that, but i want to use dropdown menu.

Dynamically add textbox using jquery

from the link above i want something like that, but i want to use dropdown menu.

here is my code

http://jsfiddle.net/boyee007/VyG6F/

the textbox will be added depends on the value.

if you select 3 will only show 3 te开发者_如何学Cxtboxes, and if 2 will only show 2 textboxes and so on


Try something like this:

$("#ppl").change(function(){

    // The easiest way is of course to delete all textboxes before adding new ones
    //$("#holder").html("");

    var count = $("#holder input").length;
    var requested = parseInt($("#ppl").val(),10);

    if (requested > count) {
        for(i=count; i<requested; i++) {
        var $ctrl = $('<input/>').attr({ type: 'text', name:'text', value:'text'});        
            $("#holder").append($ctrl);
        }
    }
    else if (requested < count) {
        var x = requested - 1;
        $("#holder input:gt(" + x + ")").remove();
    }
});

See it running here.


here is your solution...check it out....

Solution

0

精彩评论

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

关注公众号