Applescript and Safari - activating a submit button

Hi there.
I’m working on an Applescript that will automatically activate a submit button on a webpage.
Here’s the webpage’s relevant HTML:

I want to have the Applescript automatically activate this submit button. Here’s what I’ve got that’s currently not working:

tell application "Safari"
	open location ""
	delay 4
	do JavaScript "document.forms['submit']['Login1_LoginButton'].submit()"
end tell

Any help is appreciated!

First of all, this script only works with Safari 3+.

Just replace NAME with the name of the form you are submitting and LOCATION with the URL of the web page.

tell application "Safari"
if (count of windows) is 0 then make new document
	tell front window to set newtab to make new tab with properties {URL:LOCATION}
	do JavaScript "setInterval(function(){if(/loaded|complete/.test(document.readyState)){document.getElementsByName(\"NAME\")[0].submit();}}, 3)" in newtab
end tell

It uses setInterval to check for the status of page loading, which should be a more robust solution. An even better way would be to use “document.onload = function() {};”, but I couldn’t get it to work.