Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

two forms one submit button

We have two forms on one html page that submit data to two separate databases for tracking purposes, and would like them to work with one submit button. An earlier post provided a simple javascript which probably should but does not work. It appears that the first form works part way and then hangs up and the second does not start. Probably something simple but to a non programer beyond my capability. See the code below
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<SCRIPT> 
function submitBoth() 
{ 
   document.frm1.submit(); 
   document.frm2.submit(); 
   return false;
} 
</SCRIPT>
<link href="css/name_styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="frm1" action="http://www.domain.com/cgi-bin/saltercontact.cgi" method="POST">
  <div align="left">
<!--  SCRIPT CONFIGURATION SECTION -->
<input type="hidden" name="required" value="submit_by">
<input type="hidden" name="data_order"value="Name,Company_Name,Street_Address,City,State,Zip,Phone_Number,Ext,Day_Time_Phone_Number,Day_Ext,Fax_Number,submit_by,Quote,Started,Stage,Call,How_Soon,Tell_us_about_your_project">
<input type="hidden" name="submit_to" value="email@domain.com">
<input type="hidden" name="autorespond" value="yes">
<input type="hidden" name="automessage" value="mymessage.txt">
<input type="hidden" name="outputfile" value="literature.log">
<input type="hidden" name="countfile" value="idnumber.txt">
<input type="hidden" name="form_id" value="Literature Form">
<input type="hidden" name="ok_url" value="http://www.domain.com/thanks_faxquote.html">
<input type="hidden" name="not_ok_url" value="http://www.domain.com/oops.html">
<!--  END OF SCRIPT CONFIGURATION SECTION -->
 
  <p><span class="body_text">Name:
    <input type="text" size="24" name="Name">
    <br>
    <br>
    Company Name:
    <input type="text" size="24" name="Company_Name">
    <br>
    <br>
    Street Address:
    <input type="text" size="24" name="Street_Address">
    <font color="#FF0000"><b>(Needed 
    for mail)</b><br>
    <br>
    </font>City:
    <input type="text" size="12" name="City">
    State:
    <input type="text" size="6" name="State">
    Zip:
    <input type="text" size="7" name="Zip">
    <br>
    <br>
    Day Time Phone Number:
    <input type="text" size="12" name="Phone_Number">
    <br>
    <br>
    Email 
    Address:
    <input type="text" size="17" name="submit_by">
    <font color="#FF0000"><b>(Needed  to provide you with the information you have requested).</b></font></span><span class="body_text"><br>
    <br>
    Tell us about your project:</span><font size="2" face="Arial, Helvetica"><br>
    <textarea name="Tell_us_about_your_project" rows="5" cols="40"></textarea>
    </font> </p>
</form>
 
---------------------------------------------------<br>
<form name="f2" action="http://www.domain.com/cgi-bin/saltercontact.cgi" method="POST" onSubmit="submitBoth()">
  <!--  SCRIPT CONFIGURATION SECTION -->
  <input type="hidden" name="required" value="hear">
  <input type="hidden" name="data_order"value="checkbox,checkbox1,checkbox2,checkbox3,checkbox4,other">
  <input type="hidden" name="submit_to" value="email@domain.com">
  <input type="hidden" name="autorespond" value="yes">
  <input type="hidden" name="automessage" value="mymessage.txt">
  <input type="hidden" name="outputfile" value="hear.log">
  <input type="hidden" name="countfile" value="idnumber.txt">
  <input type="hidden" name="form_id" value="Hear Form">
  <input type="hidden" name="ok_url" value="http://www.domain.com/thanks_faxquote.html">
  <input type="hidden" name="not_ok_url" value="http://www.domain.com/oops.html">
  <!--  END OF SCRIPT CONFIGURATION SECTION -->
    <p>
    <span class="contact_sub_heading"><span class="body_text">Where Did You Hear About Us:</span> <br>
    <br>
    <table width="400" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="body_text">Search Engines</td>
        <td class="body_text"><input type="checkbox" name="checkbox" value="Search_Engines"></td>
      </tr>
      <tr>
        <td class="body_text">This Old House Magazine </td>
        <td class="body_text"><input type="checkbox" name="checkbox1" value="This_Old_House"></td>
      </tr>
      <tr>
        <td class="body_text">Fine Homebuilding Magazine </td>
        <td class="body_text"><input type="checkbox" name="checkbox2" value="Fine_Homebuilding"></td>
      </tr>
      <tr>
        <td class="body_text">Professional Deck Builder </td>
        <td class="body_text"><input type="checkbox" name="checkbox3" value="Deck_Builder"></td>
      </tr>
      <tr>
        <td class="body_text">Sponsored Links</td> 
        <td class="body_text"><input type="checkbox" name="checkbox4" value="Sponsored_Links"></td>
      </tr>
      <tr>
        <td class="body_text">Other (Please Specify) </td>
        <td class="body_text"><input type="text" name="other"></td>
      </tr>
    </table>
       <br>
      <br>
  <input type=submit value="Send Both">
</form>
</body>
</html>

Open in new window

0
netthing
Asked:
netthing
  • 3
  • 2
1 Solution
 
HonorGodCommented:
I believe that the issue is related to the fact that submitBoth() returns false,
regardless of the success/failure of the two submit() functions.

Try
<script type='text/javascript'> 
function submitBoth() { 
  return document.frm1.submit() && document.frm2.submit(); 
} 
</script>

Open in new window

0
 
netthingAuthor Commented:
HonorGod, thanks made progress in that the first form now successfully completes but the second does not. I tested the second separately to make sure and by its self it works. Anything I can do to help trouble shoot.
0
 
HonorGodCommented:
It may be that the completion of the submit for the first form causes the page to be reloaded...

This may not be something over which we have a great deal of control...

I wonder if you might use something like setTimeout() to cause each of the submit routines to act concurrently?  This may be risky.  We may have a situation where one completes, and forces the page to be refreshed/reloaded/reset, thus causing the other to terminate.  I don't know.

0
 
netthingAuthor Commented:
thanks, sorry for the delay in responding. Came to realize that it would not work because of the way Internet browsers function
0
 
HonorGodCommented:
Sorry that we weren't able to overcome browser shortcomings.

Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now