javascript - Add more input fields when user press button in jquery -


i new in jquery need help. have modal user enters title. when user enters title new div display div contains 1 input filed or 1 addmore button when user click on addmore button new input fields open. want user add upto 18 more fileds after user shows alert message. enter image description here

here html code:-

enter code here <div class="modal fade" id="mymodal" role="dialog"> <div class="modal-dialog">     <div class="modal-content">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal">&times;</button>             <h4 class="modal-title">add category</h4>         </div>         <div class="modal-body">             <h4>enter title</h4>             <input type="text" name="title" class="getvalue">             <button type="submit"  class="submitdata"> submit</button>         </div>          <div class="modal-footer">             <button type="button" class="btn btn-default" data-dismiss="modal">close</button>         </div>       </div>      </div> 

, jquery code

enter code here $(document).ready(function() {     var room= 1;     $(".submitdata").on('click',function(){         var value= $(".getvalue").val();         $(".submitdata").attr('disabled');         $(".modal-body").after(             '<br><center><div id="contain">              choose own service <br> <br>             <input type="text" name='+value+'[]>             <button type="button" class="addservice">add more</button>             </div></center>'             );         $(".addservice").on('click',function(){               //please coding here         });     }); 

thanks ina davance :)

try this:

html

<div id="contain">    choose own service <br> <br>   <div>   <input type="text" name='+value+'[]>   <button type="button" class="addservice">add more</button>   </div> </div> 

js

$(document).on('click', '.addservice', function(){     var html = '<div><input type="text" name="myinput"><button type="button" class="addservice">add more</button></div>';   $(this).parent().append(html); }); 

working fiddle


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -