Christian-G
Christian-G

Reputation: 2361

Autosubmit form with existing 'submit' element

I have an HTML page with 1 form on it. So to auto-submit the form I could use this:

<body onload="document.forms[0].submit()">

However, there can be an element in the form with name="submit". This breaks the above code. Apart from removing or renaming the 'submit' field, is there another way to auto-submit a form?

Cheers.

Upvotes: 0

Views: 155

Answers (2)

troutwine
troutwine

Reputation: 3831

Is there any particular reason that you'd want to keep a form element with name "submit"? Renaming that seems like it is the most pragmatic solution. Avoid name collisions when possible, and all that.

Assuming there is, give the form an ID and reference that.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318558

Give the form an id and then use document.getElementById('id-of-your-form').submit();

Upvotes: 1

Related Questions