9

Just a little thing I've always wondered:

Is it possible to submit a form on any webpage, rather than clicking the forms submit button, I want to do it from the chrome console (ctrl+shift+j in chrome)?

I've tried a couple ways but I either get an error like

Cannot use function submit on undefined

or

HTML tag has not function submit.

Any help?

PS - If you go here and try and submit the form on your right through the console click here

1
  • What have you entered in the console? On which page did you do that?
    – Bergi
    Sep 29, 2012 at 13:23

3 Answers 3

12
form = document.getElementById("frm1")
form.submit()

works on your example when viewing the standalone iframe.

0

For your example when working with an iframe:

 // from http://stackoverflow.com/questions/1452871/how-can-i-access-iframe-elements-with-javascript
 function iframeRef( frameRef ) {
     return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument
 }

 var inside = iframeRef( document.getElementsByTagName('iframe')[0] );


 // from @DeanGrobier
 form = inside.getElementById("frm1")

 form.submit()
0

It is inside an iframe in your example. In your case, you must enter this in the console for it to work:

var q = window.document.getElementsByTagName('iframe')[1];
var r = q.contentWindow.document.getElementById("frm1");
r.submit();

or, in just one line:

window.document.getElementsByTagName('iframe')[1].contentWindow.document.getElementById("frm1").submit();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.