Pixel
Pixel

Reputation: 369

Add button in jsp which will change something in the same page

my question is how to make a button in a html or jsp page which when clicked on will add something to the same page.

So if i got a jsp page called Prescription.jsp, and i got some input forms like:

ID     name   select commodity   weight   tolerance
box     box       drop down        box       box

Where box = inputs in a input form. an example you see under here.

I want the page to show only 1 input form of Id, name, commodity, weight and tolerance when the page is loaded, and if you click on "Add Commodity" in the top corner, you should add a new set of boxes under.

I don't know if this is possible, because i'm not sure where to look for the right answer.

Upvotes: 0

Views: 2164

Answers (1)

Tusar
Tusar

Reputation: 769

 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
        $(function(){
            $("#addCommodity").click(function(){                   

              $("#commdity-table tr:last").clone().find('input').val('').end().insertAfter("#commdity-table tr:last");

            });
        });
    </script>

 <table id="commdity-table">

 ....

 </table>
 <input type="button" value="Add Commodity" id="addCommodity" /> 

Upvotes: 1

Related Questions