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 onTry 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
精彩评论