Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append new text field while clicking a button and remove by clicking button in Laravel 4

i have a form with two fields such as phone, email like below image.

Form layout

when i click on the plus button , i want to append one extra text field in form below the button. and i want to remove the text field when clicking the minus button.

dynamically add the fields and set name for unique for that. i need these data to insert into table.

my html code is showed in 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>
like image 977
Jishad Avatar asked Nov 09 '22 22:11

Jishad


1 Answers

This might 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>
like image 97
Shirish Patel Avatar answered Nov 14 '22 22:11

Shirish Patel