0

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

2
  • you want to create textbox or label? Commented May 1, 2016 at 6:11
  • I want to create textboxes in the exact form shown in the image Commented May 1, 2016 at 6:44

1 Answer 1

3

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);
    }
  });
});
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.