Submit form using Greasemonkey
forms, greasemonkey, javascript, submit
Solution
It should be a simple job:
// ==UserScript==
// @name myscript
// @namespace whatever
// @include http://path to the internal page
// ==/UserScript==
document.forms[0].submit();
Problem
The first time, each day, I try to access a web page at work, I get redirected to an internally hosted web page with the IT guidelines and a form with two buttons "Agree" and "Disagree". Clicking "Agree" then allows external internet access for that day and sends you to the site you were originally looking for. I want to make a Greasemonkey script that auto-submits the form, since I already have a batch file starting up all my normal apps on boot and this would allow me to just leave the PC while it's doing its 20 minute daily start-up ;) The page only has the one form: ``` <form method="post"> <input type="submit" value="I Agree" class="agree" onsubmit="submitonce(this)" /> <input type="button" onclick="javascript:window.close();" value="I Disagree" class="disagree"/> </form> ``` And not sure if it matters, since I only need the click, but the function `submitonce` is: ``` function submitonce(theform) { //if IE 4+ or NS 6+ console.log("Submitting"); if (document.all || document.getElementById) { //screen thru every element in the form, and hunt down "submit" and "reset" for (i = 0; i < theform.length; i++) { var tempobj = theform.elements[i]; if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") //disable em tempobj.disabled = true; } } } ``` I have the rest of the source, but it doesn't look like there is anything else relevant. I haven't really coded before in Greasemonkey/JS, so any help would be appreciated. I'm playing around with an existing userscript that uses CtrlEnter to click the button. Obviously I don't care if it's a virtual "click" or just a trigger of the submit function, since I'd say they are the same thing aren't they?