Solved

HTML multiple form submit but as one single request

Posted on 2003-11-06
10
628 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 400 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with a CSS in a page 2 30
bootstrap footer centering and expand problems 7 42
How to count in a table in php 22 33
CSS: Making responsive table look nicer 7 23
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now