Jump to content

submitting form with external button & dynamic form action


shanetastic

Recommended Posts

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?

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

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. :)

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.