简体   繁体   中英

Submitting HTML form with javascript Onclick

I am trying to submit my HTML form with javascript rather than using an submit input type.

However I am presented with the following error:

Uncaught TypeError: document.getElementById(...).submit is not a function

Below is the structure of my code:

<form method="post" action="index.php" id="popup_form">
    <input type="hidden" name="page" value="popup_raffle_entry">
    <input type="hidden" name="submit" value="1"><div class="popup_wrapper"><h1 class="container_title" style="-webkit-border-radius:0px;border-radius:0px;margin-bottom:5px;">
           Raffle Entry - Galil (Factory New) | </h1><p>The price for one ticket in this raffle is <span style="color:#4E17A7;">1000 Flip Coins</span>.</p><p><span style="color:#4E17A7;">1000 Flip Coins</span> is currently equivalent to
           <span style="color:#4E17A7;">$10</span></p><br><p style="position:relative;top:0px;left:0px;font-weight:bold;">Your current Flip Coin Balance is:
    <span class="profile_category_r"><img src="images/flipcoin.jpg" style="position:absolute;left:290px;top:2px;">
           <span style="margin-left:35px;color:#4E17A7;">1000</span></span></p><p style="margin-top:10px;">Please choose the number of tickets to buy:</p><input type="text" name="number_of_tickets" id="number_of_tickets" placeholder="Between 1 and 10"></form><br clear="all"><p class="buy_tickets_button" onclick="document.getElementById('popup_form').submit();">Buy Tickets Now</p><a class="buy_flipcoins_button" href="index.php?page=purchase">Purchase Flip Coins</a><p class="close_popup_button">Close Popup</p><br clear="all"><br clear="all"></div>

I have tried moving the java script function both inline and in a scripts.js page but it doesnt make a difference.

You have a input name="submit", this is causing the problem.

Also, there is no button in your html.

我建议使用Firebug之类的工具来跟踪Javascript代码,尤其是在您的情况下,它说是否调用了commit以及返回了它。

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