View Full Version : Adding multiple items in shopping cart w/ one click

06-29-2007, 10:17 PM
Hello, I am currently building a shopping cart and I have a small problem.

On the product page, I have the option that if a customer would like to add extra "products", then they would click on the desired checkboxes to add what they would want and then when they click on the "finish purchase" link, they would be directed to the cart page with their selection or selections shown.

I build the following javascript to give the link the right value based on the selected checkboxes:

function checkTheChecks(product_id) {

var firstBox = document.forms[0].elements[0]
var secondBox = document.forms[0].elements[1]
var thirdBox = document.forms[1].elements[0]

if (firstBox.checked && secondBox.checked) {
location.href = "errorpage.html"
else if (firstBox.checked) {
location.href = "cart.php?WHAT SHOULD I PUT HERE" + product_id
else if (secondBox.checked) {
location.href = "cart.php?id2=3" + product_id
else if (firstBox.checked && thirdBox.checked) {
location.href = "cart.php?id2=5&id3=7" + product_id
else if (secondBox.checked && thirdBox.checked) {
location.href = "cart.php?" + product_id
else if (thirdBox.checked) {
location.href = "cart.php?" + product_id
else {
location.href = "cart.php" + product_id

Making multiple ids didn't work out for me, but i placed it with the code so that you could see what i've tried.

I am a beginner on PHP and MySQL, I already set the database but the problem is the way of handling multiple items in a single session variable.
Excuse me if i am a bit vague, but I will repeat myself, i am a beginner at PHP.
Any help is greatly appreciated.

Here is the link to the target site that I am working on: