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 Answers
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" />') ;
}
}
});
1 Comment
Ifeoluwapo Ojikutu
Thanks, i really do appreciate. However how do i remove an input box i dont need.
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
Ifeoluwapo Ojikutu
Thanks. I really do appreciate