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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

628 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