0

Adding two input fields at once works fine, but how can i remove two input fields as needed.

Reference : https://phppot.com/php/php-contact-form-with-custom-fields/

Example code

<div id="custom-box">
 <label class="custom-input-label">Custom Fields</label>
   <div id="custom-input-container">
      <div class="input-row">
          <input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" name="custom_name[]" /> 
          <input style="width:49%!important; float:right;" type="number" placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" name="custom_value[]" />
  </div>
  </div>
  <input type="button" class="btn-add-more" value="Add More" onClick="addMore()" />
                    </div>

and Java script to add more fields

function addMore() {
               $("<DIV>").load("input.php", function() {
                  $("#custom-input-container").append($(this).html());
            });
        }

input.php page content

<div class="input-row">
    <input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" name="custom_name[]" /> 
    <input style="width:49%!important; float:right;" type="number" placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" name="custom_value[]" />
</div>

1 Answer 1

1

I am deleting last selector of class name "input-row" and it does work. Here is the solution:

Javascript:

function deleteMore() {
           $("<DIV>").load("input.php", function() {
              $(".input-row:last").remove();
           });  
        }

HTML

<input type="button" class="btn-add-more" value="Delete More" onClick="deleteMore()" 
/>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Hell Kitchen ! Its working. it does delete last 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.