Jump to content

Submit form using javascript


sseeley

Recommended Posts

Hi I hope someone can help me. I am trying to post a form on the selection of a check box.  I am using the following code, but I get JavaScript errors in IE and Chrome.

 

echo "<form action='page2.php' method='POST' name='myform'>";
				echo "<input type='checkbox' name='this_Box' value='test' onclick='submitform()'>";
				echo "</form>";
				?>
				<script type="text/javascript">
				function submitform()
				{
					document.forms["myform"].submit();
				}
				</script>
				<?php	

 

Many thanks in advance

 

Stuart

Link to comment
https://forums.phpfreaks.com/topic/246285-submit-form-using-javascript/
Share on other sites

1. what errors?

 

2. I would declare this function in the head section of the page, as this is where it should go..

 

3. also since you are using the name attribute here and not the id attribute.. it should be written like this..

 

function submitForm()
{
document.myform.submit();
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.