sseeley Posted September 2, 2011 Share Posted September 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246285-submit-form-using-javascript/ Share on other sites More sharing options...
AyKay47 Posted September 2, 2011 Share Posted September 2, 2011 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/246285-submit-form-using-javascript/#findComment-1264780 Share on other sites More sharing options...
requinix Posted September 2, 2011 Share Posted September 2, 2011 For what it's worth, onclick="this.form.submit();" Quote Link to comment https://forums.phpfreaks.com/topic/246285-submit-form-using-javascript/#findComment-1264873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.