Mar
2
Written by:
Joel Taylor
3/2/2007
JavaScript can be very powerful when used with forms. Two of the most powerful features are submitting a form by executing JavaScript and changing the action or the script that the form will submit to. This can be very useful if a form has multiple submit buttons.
Perhaps one button could update cart information and another send the user to the checkout. In this case, when the users goes to the checkout they should be sent to an https site instead of the regular http site.
The update button can be left alone and will use the action that is in the form when the page loads. The other button could have a javaScript on click event like this (Assuming the button is inside the form tags):
Notice the syntax of this.form.action = 'script'. You could also use document.form[0].action = 'script'.
In order to submit a form based on a button click. (Assuming the button is inside the form tags)
Here is a link to www.quirksmode.org a great reference about javascript and forms.
Tags: