Go Premium for a chance to win a PS4. Enter to Win

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

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

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
Alextruj
Asked:
Alextruj
1 Solution
 
KenAdneyCommented:
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
 
Dean OBrienCommented:
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
 
cj_nepentheCommented:

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
 
YZlatCommented:
<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
 
poopallCommented:
How about an example of excatly what you want to send to the cart ?
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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