When adding a new text field, click the button and delete by clicking the button in Laravel 4

I have a form with two fields , such as phone , email , as shown below.

Form layout

when I click the plus button, I want to add one additional text box in the form below the button. and I want to delete the text box by clicking the minus button.

dynamically add fields and set a unique name for them. I need this data to insert into a table.

my html code is shown below.

<div class="RegSpLeft"><input type="text" value="Phone"></div> <div class="RegSpRight"> <a href="#"><img src="images/plus.png"></a> <a href="#"><img src="images/minus.png"></a> </div> 
+5
source share
1 answer

This can help you.

 <div class="RegSpLeft" id="phone"> <input type="text" value="Phone"> </div> <div class="RegSpRight"> <a href="#" class="pl">+ </a> <br/> <a href="#" class="mi">- </a> </div> <script type="text/javascript" src="dist/js/jquery-2.1.1.min.js"></script> <script type="text/javascript"> $(function() { $('a.pl').click(function(e) { e.preventDefault(); $('#phone').append('<input type="text" value="Phone">'); }); $('a.mi').click(function (e) { e.preventDefault(); if ($('#phone input').length > 1) { $('#phone').children().last().remove(); } }); }); </script> 
+1
source

Source: https://habr.com/ru/post/1208040/


All Articles