Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML multiple form submit but as one single request

Posted on 2003-11-06
10
Medium Priority
?
647 Views
Last Modified: 2010-04-09
What best I can do if I need to submit 2 forms at once but it has to go out as one single HTTP (post/get) request?
0
Comment
Question by:nik_c_shah
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 9695996
as one POST ... so that means you want to submit the data from two forms as if it were a single form?  If this is correct, then you can copy the fields from from2 into corresponding hidden fields in form1 and then submit form1.  Let me know if you need help with this.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9696000
"from2" should be "form2"
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9696028
combine both forms into one huge hidden master form

simple example

<html>
<body>
<form "aForm1">
<input type="text" name="num1" onkeyup="document.hiddenForm.num1.value = this.value">
</form>

<form "aForm2">
<input type="text" name="value1" onkeyup="document.hiddenForm.value1.value = this.value">
</form>

<button value="Submit" onclick="document.hiddenForm.submit()">

<form name="hiddenForm">
<input type="hidden" name="num1">
<input type="hidden" name="value1">
</form>
</body>
</html>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Bustarooms
ID: 9696030
oops sorry kEk
0
 

Author Comment

by:nik_c_shah
ID: 9696097
Since one of the forms is in an IFRAME element, can I not copy it as an object and nest it within the form I can submit ? And the forms have very large select boxes, i want to avoid parsing them and storing in arrays etc. Also how do u copy form elements (and not their contents into hidden fields)?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9696981
Bustarooms:  no worries at all.

Nik:  It would be helpful to see your code, but in general do this in the main page (the one containing the IFRame)


function copyIFrameFormElements()
{
    var iFrameForm = self.frames["nameOfTheIFrame"].document.forms["nameOfTheIForm"];
    var mainForm = document.forms["nameOfTheMainForm"];

    // if it is a text box:
    mainForm.hiddenField1.value = iFrameForm.textField1.value;

   // if it is a SELECT:
   mainForm.hiddenField2.value = iFrameForm.selectField2.options[iFrameForm.selectField2.selectedIndex].value;
}
0
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 1600 total points
ID: 9699066
>>... copy it as an object and nest it within the form I can submit

the following demonstrates concatenating 2 forms in the same page.  You would simply have to modify one of the assignments to reflect your iframe -- frames.framename.document.getElementById('formID').innerHTML;

function doit(formObj)
{
  x = document.getElementById('b').innerHTML
  y = document.getElementById('a').innerHTML
  document.getElementById('a').innerHTML += x;
  z = document.getElementById('a').innerHTML
  alert(z)


}

//-->
</script>
</head>
<body>
<form name="a" onsubmit='doit(this)'>
<textarea name='theResults' id='theResults' rows=10 cols=40 onfocus=this.blur()>1
2
4
6
</textarea>
<input type="submit">
</form>
<form name='b' id='b'>
<input type="text" value='abc'>
</form>

Vinny
0
 

Author Comment

by:nik_c_shah
ID: 9699957
Guyz thanks for all ur insight. Vincent ur trick of adding up the innerHTML and submitting is really cool. I shall settle in for that. Is there an Netscape equivalent to it?
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9700992
Hi
  if you mean nn6+, it uses innnerHTML
  if you mean nn4.7, 99.9% percent sure don't think so.  NN4.7 layers are documents in and of themselves; so, while you would be able to access individual elements within the form with something like
 document.layers[divid].document.formname.elementname,
you would then have the problem of concatenating it into the 'submit' form. Also, the div would have to be positioned absolutely -- another potential problem.  You would be better off filling hidden fields.

Vinny
0
 

Author Comment

by:nik_c_shah
ID: 9721613
Further Update on error messages:

Exception loading servlet /nmsloader/test-tags.jsp stack:
java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo: method (Ljava/lang/String;ZZLjava/lang/String;)V not found
      at org.apache.jasper.compiler.TagLibraryInfoImpl.createAttribute(TagLibraryInfoImpl.java:478)
      at org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:395)
      at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:350)
      at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:284)
      at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:696)
      at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:119)
      at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:190)
      at org.apache.jasper.compiler.Parser.parse(Parser.java:1048)
      at org.apache.jasper.compiler.Parser.parse(Parser.java:1022)
      at org.apache.jasper.compiler.Parser.parse(Parser.java:1018)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:173)
      at com.netscape.server.http.servlet.NSServletEntity.load(NSServletEntity.java:230)
      at com.netscape.server.http.servlet.NSServletEntity.update(NSServletEntity.java:149)
      at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:453)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question