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.

18
  • Maybe you have more JS which causes a problem? Do you see any errors ? Commented Jun 23, 2014 at 16:03
  • @putvande no console errors. Everything else is working fine. Commented Jun 23, 2014 at 16:03
  • Is your form loaded on the page when you try to submit it? Commented Jun 23, 2014 at 16:04
  • @Adjit out of curiosity, can you use one of those lines you proposed in the console? Commented Jun 23, 2014 at 16:04
  • 1
    This is because your submit input name is submit ... and it is restricted name that overrides form.submit() function... just rename it to something else like submiter and it will work. Commented Jun 23, 2014 at 16:33

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

3 Comments

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.
Cool, take a look at this question as well: stackoverflow.com/q/833032/1420197
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.