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
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();
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.