Add input data to a table using jquery

0

Hi, I'm trying to add data from a form to a table, but when I click the add button, I capture the values at zero. The code is as follows:

                    Pay                                                                                                                     Way to pay                   CashCredit / Debit CardChequeOther                                                  Voucher                                                                                                                     
                    Add payment                                                                                                    

              </thead>
              <tbody id="bodypago">

              </tbody>  
            </table>

          </div> 
        </div>
  </div> 
   </div> 

<script type="text/javascript">
   var cantpa= $("#cantpa").val();
   var tipopa = $("#micombo").val();
    $("#addpa").on('click', function(e){
        $("#bodypago").append("<tr><td>"+cantpa+"</td><td>"+tipopa+"</td></tr>");
    });
</script>
    
asked by lucho 05.05.2017 в 15:01
source

1 answer

0

I think you could solve it in the following way:

var cantpa= $("#cantpa").val(); 
var tipopa = $("#micombo option:selected").val(); //Creo que es un select
$("#addpa").click(function(){ 
   $("#bodypago").append($("<tr>").append(
     "<td>" + cantpa +  "</td>" +
     "<td>" + tipopa + "</td>"
   )); 
});

I hope you help, greetings.

    
answered by 05.05.2017 в 15:23