How should I automatically re-submit a form?

I have created a small PHP App that extracts stuff from a MySQL database. Five records are selected at random for extraction and showing on screen. At the bottom of the display is a form (id = ‘commentsform’) with ‘submit’ button, which will re-run the script and display a new random selection of results. Works perfectly when I click the submit button manually.

I’ve written two alternative ways of doing it, which aren’t relevant here. I want to see which way runs fastest. I’ve set up a timer on the script, which works fine, but the result of a single run is so fast I’m trying to run the script 100 times to get a better figure. So at the bottom of my script I have:

<script type='text/javascript'>
	function goAgain() {
//		var frm = document.getElementById('commentsform');
//		frm.submit();
		document.forms[0].submit();
	}
	window.onload = goAgain;
</script>
</body>
</html>

As you can see, I’ve tried two ways of accessing the form (one is commented out). In BOTH cases I’m getting a Javascript console error message “document.forms[0].submit is not a function” (or “frm.submit is not a function”).
This approach to automatically submitting a form is widely advocated on the internet, so I can’t see why it doesn’t work for me. Can anyone help here, please ?

I’m aware that if it did work there is presently no way of stopping the script, but I can probably take care of that once it works. (The PHP counts to 100, but not not the JS. The easy way might be not to display the form after 100 cycles.)

Obviously this isn’t an every-day requirement !

It’s still unclear to me why an automatic ‘submit’ on the form doesn’t work. The solution is to use '‘click’ on the submit button:

function goAgain() {
		var btn = document.getElementById('go');
//		alert ("Button is " + btn.id);
		btn.click();
	}

the function ‘goAgain’ is called after the form has loaded, and the form is now re-submitted as soon as it loads. All that remains is to link the PHP counting to the JS so that it will stop at some pre-determined number of cycles. The PHP counting uses a SESSION to preserve the count.