Onload提交无效

时间:2015-02-27 21:13:04

标签: javascript jquery

我正在尝试在页面加载时提交此表单。但由于某种原因,它不起作用。我检查了控制台是否有错误,那里似乎没有任何错误。

这是html加javascript(添加了jquery)

<script type="text/javascript">
$(document).ready(function() {
$('#new-ticket-form').submit();
});
</script>

  <form  id="new-ticket-form" action="/contact_form.html" method="post" name = "new-ticket-form"  >
        <input type="hidden" name="MAX_FILE_SIZE" value="100000000">
        <input type="hidden" name="fullname" value="JOhnny test'">
        <input type="hidden" name="order_num" value="123456">
        <input type="hidden" name="phone" value="347-489-4874">
        <input type="hidden" name="email" value="fake123@gmail.com">
        <input type="hidden" name="fromorderpage" value="yes">
        <input type="hidden" name="submit" value="Submit">
        <table>
            <tr>
                <td class="label">
                    New Ticket Subject:
                </td>
                <td class="field">
                    <select name="subject_id">
                    <option value="0">Select one ...</option>';
                    <option value="123">Confirm Delivery Appointment</option>';
                    <option value="124"> Reschedule Delivery Appointment</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="label">
                    Summary:
                </td>
                <td class="field">
                    <input type="text" name="summary" value="This is a test disregard">
                </td>
            </tr>
            <tr>
                <td class="label">
                    Your Message:
                </td>
                <td class="field">
                    <textarea name="usr_msg" placeholder = "This is a test disregard">This is a test disregard</textarea>
                </td>
            </tr>

            <tr>
                <td class="submit" colspan="2"><input type="submit" value="Submit Ticket" name = "btn_submit">  
                </td>
            </tr>
        </table>
    </form>

2 个答案:

答案 0 :(得分:3)

删除隐藏的输入字段<input type="hidden" name="submit" value="Submit"> - 然后它可以正常工作。

工作jsFiddle:http://jsfiddle.net/3bo4rgvw/3/

答案 1 :(得分:1)

我有未捕获的ReferenceError:$未定义。 jQuery没有定义, 但你可以使用

$(document).ready(function() {
  document.getElementsByName('btn_submit')[0].click();
});
在你的readyState循环中