Dave's Brain

Browse - programming tips - javascript programatically submit a form

Date: 2009nov9
Language: javaScript

Q.  How can I programatically submit an HTML form?

A.  Call the form's submit method.  If you only have one form:

	function submitTheForm() {
		if (document.forms.length == 0) return false;
		document.forms[0].submit();
	}

If you have multiple forms:

	<form id=the_second_form>
	</form>

	<script>
	function submitSecondForm() {
		var	obj;

		obj = document.getElementById('the_second_form');
		obj.submit();
	}
	</script>
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.