Thursday 31 July 2008

Enable an HTML Form to Submit to Multiple Locations Using Javascript

This is a simple solution to allow a single html form to submit to multiple locations.

<form name="myform" method="post" action="noscriptPage.php">
...
<input type="submit" name="submit" value="Update"
onclick="document.myform.action='updatePage.php';"/>
<input type="submit" name="submit" value="Submit"
onclick="document.myform.action='submitPage.php';"/>
</form>

Add the multiple submit buttons to the form, each with a Javascript onclick clause to change the forms action property, to the desired action page.

Easy.

Optionally you can also cater for users with Javascript disabled, by adding a default action to the form, to either go to a message page, forward page that can determine the button pressed and forward.

No comments: