shanetastic Posted May 17, 2012 Share Posted May 17, 2012 Here is the code for test.html: <html> <head><title></title></head> <body> <script type="text/javascript"> function OnSubmitForm(){ document.myform.action ="insert.html"; return true; } </script> <form name="myform" onsubmit="return OnSubmitForm()" method="get"> <input type='radio' name='Search' value='test'>test</input> </form> <a href='javascript:document.myform.submit()'><img src='images/buttonnext.jpg'></a> </body> </html> The way I want it to work: when the img (buttonnext.jpg) is clicked, the form is submitted. When the form is submitted it runs the javascript, which sets the action to be that insert.html is loaded. i.e. the end result should be to redirect to insert.html?Search=test The way that it is working now: the page is redirected to test.html?Search=test What do I need to change to accomplish my goal? Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/ Share on other sites More sharing options...
The Letter E Posted May 18, 2012 Share Posted May 18, 2012 You're missing the form action. Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346535 Share on other sites More sharing options...
shanetastic Posted May 18, 2012 Author Share Posted May 18, 2012 I don't believe that is correct. The javascript that is called sets the action (at least it is supposed to). If I use a traditional submit button (a submit input field inside the form) it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346558 Share on other sites More sharing options...
shanetastic Posted May 18, 2012 Author Share Posted May 18, 2012 Solved. Changing the href to: <a href='javascript:if(OnSubmitForm())document.myform.submit()'> gets it working! Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346606 Share on other sites More sharing options...
The Letter E Posted May 18, 2012 Share Posted May 18, 2012 Solved. Changing the href to: <a href='javascript:if(OnSubmitForm())document.myform.submit()'> gets it working! What's the point of setting the action with a javascript function? Just seems like code you don't need. You can just as easily use the standard action attribute and submit the form on an external click event. fyi Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346697 Share on other sites More sharing options...
shanetastic Posted May 19, 2012 Author Share Posted May 19, 2012 I was only showing a simplified version of the page. The full version sets the action to one of multiple things based on some criteria. Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346731 Share on other sites More sharing options...
The Letter E Posted May 19, 2012 Share Posted May 19, 2012 I was only showing a simplified version of the page. The full version sets the action to one of multiple things based on some criteria. I was thinking there may be more to it. Glad you got it sorted. Sorry if I informed you of something you already knew. Quote Link to comment https://forums.phpfreaks.com/topic/262701-submitting-form-with-external-button-dynamic-form-action/#findComment-1346780 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.