java - How to pass the dynamic added values into servlet -


i want value

name="product' + counter + '"

its dynamic values when click add crate row, can 1 tell me how dynamic values , how should pass servlet , how can in servlet. using form submission : jsp , java env.

$("#addrow").on("click", function () {         counter++;          var newrow = $("<tr>");         var cols = "";         cols += '<td><input type="text" name="product' + counter + '"/></td>';         cols += '<td><input type="text" name="price' + counter + '"/></td>';         cols += '<td><input type="text" name="qty' + counter + '"/></td>';         cols += '<td><input type="text" name="linetotal' + counter + '" readonly="readonly"/></td>';         cols += '<td><a class="deleterow"> x </a></td>';         newrow.append(cols);         alert(cols);         $("table.order-list").append(newrow);     }); 

no need add counter, change code this.

$("#addrow").on("click", function () {         counter++;          var newrow = $("<tr>");         var cols = "";         cols += '<td><input type="text" name="product"/></td>';         cols += '<td><input type="text" name="price"/></td>';         cols += '<td><input type="text" name="qty"/></td>';         cols += '<td><input type="text" name="linetotal" readonly="readonly"/></td>';         cols += '<td><a class="deleterow"> x </a></td>';         newrow.append(cols);         alert(cols);         $("table.order-list").append(newrow);     }); 

and in servlet array of values linked each input box below code.

string[] products = request.getparametervalues("product"); string[] prices= request.getparametervalues("price"); string[] qtys= request.getparametervalues("qty"); string[] linetotals = request.getparametervalues("linetotal"); 

edit added complete code

<html> <head>  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>   </head> <body> <form id="validationform" name="validationform" method="get" action="bg_form">  <table class="order-list" style="margin-left: 228px;">     <thead>         <tr><td>product</td><td>price</td><td>qty</td><td>total</td></tr>     </thead>      <tbody>         <tr>             <td><input type="text" name="product"></td>             <td><input type="text" name="price">             </td><td><input type="text" name="qty"></td>             <td><input type="text" readonly="readonly" name="linetotal"></td>             <td><a class="deleterow"> x </a></td>         </tr>     </tbody>      <tfoot>         <tr>             <td style="text-align: center;" colspan="5">                 <input type="button" value="add product" name="addrow" id="addrow">              </td>         </tr>          <tr>             <td colspan="5">                 grand total: rs<span id="grandtotal"></span>             </td>         </tr>         <tr>         <td>         in words <span id="inwords" ></span>          </tr>         <tr>                 <td>                 <input type="submit"/>          </tr>     </tfoot> </table>  <form>    <script>     $("#addrow").click(function(){       var newrow = $("<tr>");               var cols = "";               cols += '<td><input type="text" name="product"/></td>';               cols += '<td><input type="text" name="price"/></td>';               cols += '<td><input type="text" name="qty"/></td>';               cols += '<td><input type="text" name="linetotal" readonly="readonly"/></td>';               cols += '<td><a class="deleterow"> x </a></td>';               newrow.append(cols);         $("table.order-list").append(newrow);     });  </script> </body> </html> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -