1

I'm a rookie programmer trying to achieve something that would function this way. I have one text box displaying with a button which says add new text box. Onclick of a button named add new field, jquery shows a new text field. So if a user clicks it they can add more than one field at a time. I'll appreciate if i can get help with this. Thanks everyone.

2
  • 1
    Nice story... but what's the question with it? Commented May 23, 2013 at 23:19
  • http://api.jquery.com/appendto/ Commented May 23, 2013 at 23:21

2 Answers 2

1

rough example

$('#btn').on('click', function () {
    var num = parseInt($('#num').val(), 10);
    if (!isNaN(num)) {
          var $div = $('#div');
        for(var i=0;i< num;i++) {
             $div.append('<input type="text" />')   ;
        }
    }
});

Check Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i really do appreciate. However how do i remove an input box i dont need.
0

within your jquery you can try this

$('.buttonClass').click(function(){
     $("<input placeholder='this is a new textbox'/>").appendTo('body');
});

two things to note: you will definitely want to set a int variable that will increment each time you make a new textbox and assign them each a unique name / id so you can grab then data from them easier

and you will want to append these elements to your form rather than to the 'body' of the document

1 Comment

Thanks. I really do appreciate

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.