Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a form using javascript without knowing the name

To use the form submit javascript function you need to know the name of the form.

document.forms["myform"].submit();

or

document.myform.submit();

to submit

<form name="myform">...</form>

In my case i have a completely random name as form name. What I do know is that there is always only one form element present at the page. Any ideas to submit the form using javascript?

<form name="145f88f84584594">...</form>
like image 917
Roel Veldhuizen Avatar asked Dec 06 '25 08:12

Roel Veldhuizen


2 Answers

document.forms holds all forms.

This should work: document.forms[0].submit();.

like image 162
Dennis Avatar answered Dec 08 '25 21:12

Dennis


document.getElementsByTagName("form")[0].submit();

or if you're using jQuery:

$("form:first").submit();
like image 30
Alex Peattie Avatar answered Dec 08 '25 22:12

Alex Peattie