We help IT Professionals succeed at work.

Can forms be nested on a page?

edmac asked
I have a web page with multiple forms. I would like to email the complete page when it is finished.. Can the forms be nested within a form to submit the email?
Watch Question

Top Expert 2013


You can have more than one form on the page but they cannot be nested.  The solution is
put hidden fields on the first form.  When the second form is completed the fields get moved
to the hidden forms on the first form and are submitted with it.


And define 'email the complete page'

It's better NOT to try to create an HTML email. It's much easier to create a neatly formatted regular email that everybody can read, and add a link to a web page if you feel it necessary.

If what you're generating is an order, or an order confirmation, HTML formatting really isn't necessary anyway.


How are the hidden fields updated from the other forms?
updating the hidden fields ?
you can do it in many ways
say you have a text txt1 whose value is to be copied to a hidden field hid1
for this you can use event like onchange of the text , so every time the text changes , the new change is copied to the corresponding hidden field
write this on the onchange event of the text field txt1
window.document.all.hid1.value = window.document.all.txt1.value

or if you have a submit button then
on the onsubmit event you can write such multiple value assignments to copy the values of more then one HTML controls/fields to their corresponding hidden fields

Top Expert 2013
sorry edmac, I didn't see your last comment, it must have been during the tch problems on the site.

Okay hidden field population.
In the first form let's say you have:

<form name="form1" action="JavaScript:passValues()">
  <input type="text" name="text1">
  <input type="text" name="text2">
  <input type="submit">

In the second form:

<form name="form2" action="script.cgi">
<input type="hidden" name="text1">
<input type="hidden" name="text2">
  then all the other fields
<input type="submit">

The submit on the first form will transfer the field values usng a script which goes in the head like this:

<script language="JavaScript">
   function passValues()

Top Expert 2013

Glad I could help. Thanks for the A. :^)


Explore More ContentExplore courses, solutions, and other research materials related to this topic.