使用javascript Onclick提交HTML表单

时间:2015-08-18 18:47:27

标签: javascript html forms onclick

我正在尝试使用javascript提交HTML表单,而不是使用submit输入类型。

但是我遇到以下错误:

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

以下是我的代码的结构:

<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>

我尝试过内联和在scripts.js页面中移动java脚本函数,但它并没有什么区别。

2 个答案:

答案 0 :(得分:1)

您输入的名称=“提交”,这会导致问题。

此外,你的html中没有按钮。

答案 1 :(得分:-1)

我建议使用像Firebug这样的工具来跟踪Javascript代码,特别是在你的情况下,如果提交被调用并返回它,则说。