D
D
DooX2021-06-18 14:13:55
JavaScript
DooX, 2021-06-18 14:13:55

How to get the value of all inputs from the form when clicking on the button?

I have generated forms, when you click on the TAKE button, js should collect input data from this form and send it to the server.
How to get this data?

<form name="1">
        <div class="voucher-offer">
        <input type="hidden" name="id" value="11">
        <input type="hidden" name="title" value="11">
        <input type="hidden" name="cena" value="11">
        
        <div id="buynow">
          <button class="stripe-button voucher-offer__btn">TAKE</button>
        </div>
</form>
        <form name="2">
        <div class="voucher-offer">
        <input type="hidden" name="id" value="22">
        <input type="hidden" name="title" value="22">
        <input type="hidden" name="cena" value="22">
        
        <div id="buynow">
          <button class="stripe-button voucher-offer__btn">TAKE</button>
        </div>
</form>
        <form name="3">
        <div class="voucher-offer">
        <input type="hidden" name="id" value="33">
        <input type="hidden" name="title" value="33">
        <input type="hidden" name="cena" value="33">
        
        <div id="buynow">
          <button class="stripe-button voucher-offer__btn">TAKE</button>
        </div>
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-06-18
@DooX

new FormData(document.querySelector('form[name="3"]'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question