Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to append/add set of input field in a form with just once click?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.58k
    Comment on it

    I designed my form with writing this script below. In this script showing $(wrapper).append() will trigger the action of adding the input boxes or any thing that you put inside it. For ex I used name, email and phone input text boxes. All you just need to remember give the name with "[]" to text boxes since they are multiple

        $(document).ready(function() {
            var max_fields      = 10; //give the max no of inputs
            var wrapper         = $(".input_fields_wrap"); //this is field wrapper or you can say div class
            var add_button      = $(".add_field_button"); //add the class to your button 
            var x = 1; //initlal text box count
                if(x < max_fields){ 
                    x++; //text box increment
                    $(wrapper).append('<div><input type = "text" name = "name[]"><input type = "text" name = "phone[]"><input type = "text" name = "email[]"><a href="#" class="remove_field">Remove</a></div>'); 
            $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
                e.preventDefault(); $(this).parent('div').remove(); x--;

    And the html form code will be go like this

     <div class=" input_fields_wrap" >
    <input type="text" name="name[]">
     <input type="text" name="email[]">
     <input type="text" name="form[]">
     <h3>Want to add more<a href="#" class="add_field_button">click here</a></h3>

    Hope it might be helpful to you.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: