HTML Form - Multiple actions (not simultaneous)

Greetings,

I am having trouble with something. I have a form with a lot of data, but I would like to have two buttons at the bottom of the form, one a “Save” button (which refreshes the screen, but saves all the data for the user) and another “Submit” button (which saves the data and goes to another screen).

So far, I am only able to “save” form data by submitting the form and reading the data on the next screen. How would one accomplish saving data through two separate actions?

Please note, I am not looking to do multiple actions per submit (one action that determines “what do do next” would be sufficient), but one of several actions per submit.

I hope this was clear. Thank you in advance for your help.

if i understand correctly, u want the same form to submit data to two different forms on clicking two different buttons…like if the user clicks save it should go to save form and if clicks on submit, go to submit form…but the form should be common!

if this is the case, you can use the following layout …

<html>
	<head>
		<script language="javascript">
			function validate(mode) {
				// do all the form validation stuff you need here
				
				if(mode==1) // this means user clicked on save button
					document.forms['userfrm'].action = "savepage.php"; // set the form action to save related server page
				else if(mode==2) // this means user clicked on submit button
					document.forms['userfrm'].action = "submitpage.php"; // set the form action to submit related server page
					
				// then you can simply submit the form using javascript
				document.forms['userfrm'].submit();	
			}
		</script>
	</head>
	<body>
		<form id="userfrm" method="post">
			<!-- create all the list of controls u need here -->
			<!-- create all the list of controls u need here -->
			<!-- create all the list of controls u need here -->
			
			<input type="button" value="Save" onclick="validate(1)" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" value="Submit" onclick="validate(2)" />
		</form>
	</body>

the outline of this logic is that, we do not set the action of the form right away. we also do not use submit buttons. Instead, we use generic buttons and set a javascript function to their onclick event making them call same function but with different mode values. then in the javascript function, we decide the action of the form based on the mode value and submit the form.

Sponsor our Newsletter | Privacy Policy | Terms of Service