简体   繁体   中英

submit form from link outside form

I cannot figure out why this is not working. Any help would be much appreciated. Simply trying to submit my form with an outside link.

HTML:

<li><a href="#" id="paymentLink">Payment</a></li>

Note: that link is right above the form.

Javascript:

<script type="text/javascript">
    $(document).ready(function () {
        $("#paymentLink").click(function () {
            console.log("clicked!");
            $("#deliveryForm").submit();
        });
    });
</script>

Note: "clicked!" does show in my console when clicking the link.

Can you please use this way.

<a href="#!" onclick="event.preventDefault();document.getElementById('deliveryForm').submit();">Payment</a>

<form id="deliveryForm" action="action.php" method="POST">
   <!-- Your Form Content Here -->

</form>

I think this way will work for you, this is very simple and shorter way.

Thank You :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM