?
Solved

HTML multiple form submit but as one single request

Posted on 2003-11-06
10
Medium Priority
?
646 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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.
Find out what you should include to make the best professional email signature for your organization.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: blockā€¦
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

719 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