...

View Full Version : Client side cart need help validating form



jumpink
05-15-2007, 01:08 PM
I have a client side shopping cart. The problem is with my form. If someone does not choose a size it will still add to cart. I want a window to pop up saying please choose a size if none has been chosen. I have entered some code to try to validate the form but it is not performing correctly. Any help would be great.
Thanks
<form action = "javascript: void 0;"
method = "post"
onsubmit = "SetDesc ('shirt');
if(document.getElementById('size').selectedIndex < 1) {
window.event ? window.event.returnValue = false :e.preventDefault = true;alert('Please select a size');
}
SetCode ('ts00014');
SetImg ('images/cartimage/shirt.gif');
SetPcat (2);
if (ReadForm (this, true))
CallView ();
ClearAll ();
return false;">

$17.95 -
<input type="hidden" name="initer" value=" @0" />
<select id="size" size="1" name="size">

<option selected value="Select a size">Select a size</option>
<option value = "Small @17.95">Small</option>
<option value = "Medium @17.95">Medium</option>
<option value = "Large @17.95">Large</option>
<option value = "X-Large @17.95">XL</option>
<option value = "2XL @19.95">2X ($2)</option>
</select>
<input type = "submit"
name = "submit"
value = "add to cart" />

<br /><br />
Input <b>Quantity</b> to order -
<input type = "text"
name = "qty"
value = "1"
size = "4" />
<br /><br />
</p>
</form>

smalldog
05-15-2007, 01:29 PM
Hi Jumpkin.. I have never seen action = "javascript: void 0;" in form tag.

Use rather something like this:



<script>
function Validate()
{
if(document.getElementById('size').selectedIndex < 1)
{
alert('Please select a size');
return;
}
document.sizeform.submit();
}
</script>

<form method="post" name="sizeform">
<select id="size" size="1" name="size">
<option selected value="Select a size">Select a size</option>
<option value = "Small @17.95">Small</option>
<option value = "Medium @17.95">Medium</option>
<option value = "Large @17.95">Large</option>
<option value = "X-Large @17.95">XL</option>
<option value = "2XL @19.95">2X ($2)</option>
</select>
<input type="button" value="add to cart" onclick="Validate();">
</form>

jumpink
05-15-2007, 04:04 PM
Small dog,
Thanks but it didn't work. The pop did show up when nothing was chosen but if a selection was made it did not send the item to the cart.
Here is the where I got my original code from http://members.aol.com/paypalcart/index1.html

smalldog
05-15-2007, 04:32 PM
Jumpink :) it was an example of course.. you need to use other inputs too in your form.. (and edit JS) that was just demonstration :)

So I don't know your code but try this.....



<script>
function Validate()
{
if(document.getElementById('size').selectedIndex < 1)
{
alert('Please select a size');
return;
}
SetDesc ('shirt');
SetCode ('ts00014');
SetImg ('images/cartimage/shirt.gif');
SetPcat (2);
if (ReadForm (document.sizeform, true))
CallView ();
ClearAll ();

document.sizeform.submit();
}
</script>

<form method="post" name="sizeform">
$17.95 -
<input type="hidden" name="initer" value=" @0" />
<select id="size" size="1" name="size">
<option selected value="Select a size">Select a size</option>
<option value = "Small @17.95">Small</option>
<option value = "Medium @17.95">Medium</option>
<option value = "Large @17.95">Large</option>
<option value = "X-Large @17.95">XL</option>
<option value = "2XL @19.95">2X ($2)</option>
</select>
<input type="button" value="add to cart" onclick="Validate();">
<br /><br />
Input <b>Quantity</b> to order -
<input type = "text"
name = "qty"
value = "1"
size = "4" />
<br /><br />
</form>

jumpink
05-15-2007, 04:57 PM
Awesome, Awesome, Awesome! Thanks!
If I added another form for color would that be too complicated or should I just make size and color one form? Also the alert box says [Javascript application] can I customize this?

smalldog
05-15-2007, 05:03 PM
Javascript application you mean in the title of alert box? No you can't customize that.. and color.. just try to insert input for color to your "sizeform" <form>.. may be it will work - depends on your server side script part.

jumpink
05-16-2007, 05:53 AM
Thanks again. I know you said that the alert box is not customizable but I was wondering if there was a workaround. This site http://www.dustybrand.com/shirts/booty_gray.html
If you click add to cart without making a selection take notice of the header It says The page at blank blank says: I have seen this on different sites, just wondering if there is an easy way to do this.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum