Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    dynamic action & submit button outside of form

    Here is the code for test.html:
    Code:
    <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

    Note: If I use a submit button that is part of the form (i.e. input field with type "submit") the page is redirected correctly.

    What do I need to change to accomplish my goal?

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You are correct, when the form is submitted it is NOT running the javascript. That's pretty much the problem in a nutshell. I need to figure out why not.

    The action needs to be defined in a javascript function because it is going to be dynamic (i.e. if x then go to one page, if y go to a different page).

    It's odd to me that if the submit button is part of the form (input type submit) then everything works correctly. The href button I am using is definitely submitting the form, it just doesn't run the script. If both ways submit the form, why is only one way calling the script?

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 Posts
    <a href='javascript:if(OnSubmitForm())document.myform.submit()'>

  • Users who have thanked DaveyErwin for this post:

    cu_shane (05-18-2012)

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DaveyErwin View Post
    <a href='javascript:if(OnSubmitForm())document.myform.submit()'>
    Perfect. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •