Solved

Can a html form send two actions (two items to a cart) from one click of a button.

Posted on 2003-11-17
5
372 Views
Last Modified: 2010-04-06
I need to send two items to a cart when the user click on the submit button on an html form.  Can i create two actions from the same form.  I need two send the items separately.
0
Comment
Question by:Alextruj
5 Comments
 
LVL 10

Expert Comment

by:KenAdney
ID: 9765450
Sure.  How are you processing the form?  PHP?  ASP?  I'm assuming you want to update a database with the info.  What kind of database?  Do you need an email notification?
0
 
LVL 12

Accepted Solution

by:
Dean OBrien earned 50 total points
ID: 9765471
create a dummy hidden form.  assign matching values, then submit both on submit.  

try this.....

<html>
<head>
<script>
function copy()
{

  form2.item1.value = form1.item1.value
  form1.submit()
  form2.submit()
}
</script>
</head>
<body>
<form name='form1'>
<input type = 'text' id='item1'>
<input type ='button' value='submit' onclick='copy()'>
</form>
<form name='form2'>
<input type = 'hidden' id='item1' value='init'>
</form>
</body></html>

Give each form an action

hope this helps

Easynow
0
 
LVL 1

Expert Comment

by:cj_nepenthe
ID: 9783690

Hi,

Unfortunately you can't have more than one action attribute on an HTML <form>.  However you can get around this problem by using a bit of scripting.  When the use clicks a submit button, you can call a JavaScript function that will take the values from your form and post them to two form handler pages that will update your database.  Try the following code snippet.  When the user clicks the "Send items to cart" button, details of the itemName1 and itemName2 form fields are posted seperately to a form handler (add-to-cart.asp).  Good luck!

<script language="javascript">

      function sendBothItemsToCart() {
            sendItemToCart(document.getElementById('itemName1').value);
            sendItemToCart(document.getElementById('itemName2').value);
      }

      function sendItemToCart(vstrItemName) {    
            var objHttp = new ActiveXObject("Msxml2.XMLHTTP");
            objHttp.open("post", "http://myserver/add-to-cart.asp", false);
            objHttp.send('item=' + escape(vstrItemName));
            // (error checking here...)
      }

</script>

<form>
<input type="button" value="Send items to cart" onclick="sendItemsToCart()">
<input type="hidden" name="itemName1" value="Product1">
<input type="hidden" name="itemName2" value="Product2">
</form>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9788094
<form name="form1" method="post" action="newpage.asp?item1=<%=myItem1%>&item2=<%=myItem2%>">
<input type="text" name="item1" value=<%=myItem1%>
<input type="text" name="item2" value=<%=myItem2%>

<input type=submit" name="submit1" value="Submit Form">
</form>
0
 
LVL 2

Expert Comment

by:poopall
ID: 9805671
How about an example of excatly what you want to send to the cart ?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
WSDL Soap Error 12 281
Build and evolve an interactive experience 1 96
Coova-Chilli can't work with URL using HTTPS! 3 278
use of cookies and regulations 1 100
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

820 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