We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Need help with form input

Melody Scott
Melody Scott asked
on
Medium Priority
234 Views
Last Modified: 2012-05-06
Hi,

On this web page:

http://test dot magickitchen dot com slash menu slash MKMeals slash MKMP14 dot html

I have a form. I'm trying to adapt it from the code I've pasted here that usually adds an item to the cart. But I want the checkboxes to allow me to add more than one item to the cart. No more than two, though. Is that possible? I can't access the back end, that's written by our developer, I'm trying to get around that.
<tr class="Body"> 
              <form method="post"  action="/cgi/cart.cgi">
                <input type="hidden" name="cmd" value="add" />
                <input type="hidden" name="sku" value="17113" />
                  <td width="94" class="ItemTitle">7 Servings </td>
                  <td width="62" align="right" class="ItemTitle">$65.00</td>
                  <td width="62" align="right"><input name="qty" size="2" maxlength="6" value="1" type="text"></td>
                  <td width="108" align="center"><input type='image'  name="submit" border="0" src="/img/mkitchen/add_cart-2.gif"></td>
              </form>  
                </tr>

Open in new window

Comment
Watch Question

What is the ned to check box? You have a textbox to specify the number of items to add right (Line 7). We can restrict that to have a value of max 2. Is thsi what you want?

Author

Commented:
I want the customer to be able to select meal pack one and meal pack three, OR Meal pack four and Meal Pack five, etc. I want them to be able to select any two they would like, and have those two meal packs go to the cart.
But then again it depends on how your cart.cgi has been coded. We can change the html but it might not work properly because cart.cgi had not been coded to take care of this situation

Author

Commented:
I understand- this is a test site, so let's try it and see if it works, ok?
How many meal packs do you have on the site?
Do you have any idea why the following hidden fields are used for?

<input type="hidden" name="cmd" value="add" />
<input type="hidden" name="sku" value="17113" />

Author

Commented:
I have sic meal packs, and the hidden fields are to add an item to the cart and the SKU of the pack.
What is sku and what does the id represent? I will in the meantime so the html page

Author

Commented:
A SKU is a retailers code for an item they are selling. In this case, 17113 is the SKU for Meal Plan one, 27113 is the SKU for Meal Plan two, etc.
This is how the HTML will be but I am 100% certain that it will not work as you will need to change the cart.cgi file
<html>
<head>
    <script language="javascript">
        function Validate() {
            var checkBoxes = document.getElementsByTagName("input");
            var countSelected = 0;
            for (var i = 0; i < checkBoxes.length; i++) {
                if (checkBoxes[i].type == "checkbox" && checkBoxes[i].selected) {
                    countSelected++;
                    if (countSelected > 2)
                        break;
                }
            }
            if (countSelected > 2) {
                alert("Please select only two items to add");
                return false;
            }
            else
                document.forms[0].submit();
        }
    </script>
</head>
<body>
<form method="post"  action="/cgi/cart.cgi">
    <input type="hidden" name="cmd" value="add" />
<table cellpadding="0" cellspacing="0">
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku1" value="17113" /><input name="qty1" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item1"></td>
</tr>
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku2" value="17113" /><input name="qty2" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item2"></td>
</tr>
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku3" value="17113" /><input name="qty3" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item3"></td>
</tr>
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku4" value="17113" /><input name="qty4" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item4"></td>
</tr>
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku5" value="17113" /><input name="qty5" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item5"></td>
</tr>
<tr class="Body"> 
    <td width="94" class="ItemTitle">7 Servings </td>
    <td width="62" align="right" class="ItemTitle">$65.00</td>
    <td width="62" align="right"><input type="hidden" name="sku6" value="17113" /><input name="qty6" size="2" maxlength="6" value="1" type="text"></td>
    <td width="108" align="center"><input type="checkbox" name="item6"></td>
</tr>
<tr>
    <td colspan="4"><input type='image'  name="submit" border="0" src="/img/mkitchen/add_cart-2.gif" onclick="return Validate();"></td>
</tr>
</table>
</form>  
</body>
</html>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks- you're right, it doesn't work because of cart.cgi, but you did give me the right answer. Thanks for your help!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.