Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q190 How do you combine two forms before submitting them as one form?

irt.org | Knowledge Base | JavaScript | Form 10.2 | Q190 [ previous next ]

Q190 How do you combine two forms before submitting them as one form?

In one of the forms, or perhaps in a third form, have hidden form fields which you can then copy the contents of the visible form fields to and then submit that form.

You'll need to trap the users form submission and cancel it, and then you'll need to copy the data, and then you'll need to submit the require form:

<SCRIPT LANGUAGE="JavaScript"><!--
function copydata() {
    document.formthree.mytextone.value = document.formone.mytextone.value;
    document.formthree.mytexttwo.value = document.formtwo.mytexttwo.value;
    document.formthree.submit();
    return false;
}
//--></SCRIPT>

<FORM NAME="formone" onSubmit="return copydata()">
Enter some text: <INPUT TYPE="text" NAME="mytextone">
<P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
</FORM>

<FORM NAME="formtwo" onSubmit="return copydata()">
Enter some text: <INPUT TYPE="text" NAME="mytexttwo">
<P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
</FORM>

<FORM NAME="formthree">
<INPUT TYPE="HIDDEN" NAME="mytextone">
<INPUT TYPE="HIDDEN" NAME="mytexttwo">
</FORM>

Note, if the action of the third form is mailto: then it'll fail without telling you (a security hobble). Any onSubmit event handler of the third form will not be invoked, so make sure you perform your form validation before the line document.formthree.submit()

Feedback on 'Q190 How do you combine two forms before submitting them as one form?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.