2

Cannot get my form to submit programmatically, despite trying several ways. Tried pure JS, also tried jQuery. No success.

I have this form tag :

<form action="https://docs.google.com/forms/d/13zex8ZsEsnZz3A8uB4jU4oDb5wZfaqqq2Pq2CGlIe6M/formResponse" method="POST" id="ss-form" target="_self" onsubmit="" name="eForm">
    <!--My Form Stuff-->
    <input type="submit" name="submit" value="Submit" id="ss-submit">
</form>

Here is what i've tried :

/*jQuery*/
$('#ss-form').submit();

/*Javascript*/
document.getElementById('ss-form').submit();
document.eForm.submit();

None of them work. Not sure why, but I am assuming it has something to do with me trying to submit a google form. If I physically click the submit everything works fine.

Any and all help is greatly apprecaiated.

Adjit
  • 10,134
  • 12
  • 53
  • 98

1 Answers1

10

The problem is that you have a field (HTMLInputElement) with name submit in the form. That's why document.getElementById('ss-form').submit is not a function but an object.

So, you get the following error:

TypeError: object is not a function

The solution is to remove that element. We should be careful to verify if browser thinks it's an element and not a function:

if (typeof document.getElementById('ss-form').submit === "object") {
    document.getElementById('ss-form').submit.remove();
}
document.getElementById('ss-form').submit();
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • 1
    Nailed it! I thought I had checked that... because I recall seeing that issue elsewhere. Needless to say, thanks for all the help... spent way too long scratching my head on this one. – Adjit Jun 23 '14 at 16:26
  • Cool, take a look at this question as well: http://stackoverflow.com/q/833032/1420197 – Ionică Bizău Jun 23 '14 at 16:30
  • Thats exactly where I saw it when I was looking how to programmatically submit a form. Don't know why I didn't realize it sooner. – Adjit Jun 23 '14 at 16:33