0

I'm trying to submit this form when the page loads. But for some reason it doesn't work. I checked the console for errors and nothing seems to be wrong there.

Here's the html plus javascript(added the 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>
Laerte
  • 7,013
  • 3
  • 32
  • 50
user2809321
  • 196
  • 1
  • 3
  • 17

2 Answers2

4

Remove the hidden input field <input type="hidden" name="submit" value="Submit"> - Then it works.

Working jsFiddle: http://jsfiddle.net/3bo4rgvw/3/

Mario Werner
  • 1,771
  • 14
  • 24
  • 3
    For reference, see "Additional Notes" in the [jQuery submit() documentation](http://api.jquery.com/submit/): `Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method.` – showdev Feb 27 '15 at 21:37
1

I have Uncaught ReferenceError: $ is not defined. jQuery not defined, but you can use

$(document).ready(function() {
  document.getElementsByName('btn_submit')[0].click();
});

in your readyState loop.

Adrien
  • 365
  • 3
  • 9
  • 1
    In the question's comments, the OP stated that he has included the jQuery library although it does not appear in his posted question. Also, your code still references jQuery. – showdev Feb 27 '15 at 21:54
  • removing "submit" input name is better – Adrien Feb 27 '15 at 21:54
  • yeah I felt too lazy to writte the entire readyState loop in pure javascript ;) – Adrien Feb 27 '15 at 21:56