I want to add textboxes dynamically to a web form on the click of a button. The number will be provided in a textbox. For better understanding an image is given below: Dynamic TextBoxes
1 Answer
you need to use append() method to add new elements dynamically to DOM. I have created a demo for better understanding here : https://jsfiddle.net/p2hr1a1f/
HTML
<input type="text" class="noTxt">
<button class="btnCreate">
Create
</button>
<div class="txtBox-container">
</div>
jQuery
$(document).ready(function(){
$('.btnCreate').on('click', function(){
var txtBox="<input type='text' class='newtxtBox'><br>";
l=$('.noTxt').val();
console.log(l);
for(var i=1;i<=l;i++){
$('.txtBox-container').append(txtBox);
console.log(txtBox);
}
});
});
1 Comment
Prasanta Biswas
this is not the thing I want...the textboxes will be added one after anoher horizontally for a fixed width and the row is full it will move to the next row.