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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now