Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
377 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
[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
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 150 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

722 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