View Full Version : Form validation script for client side cart

05-15-2007, 11:19 AM
Required field(s) validation


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. Not sure where or how to use the Required field(s) validation script.
<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>
<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 />

05-15-2007, 12:36 PM
try ?

if(document.getElementById('size').value == "Select a size") {

05-15-2007, 01:43 PM
I tried but it was unsuccessful.

05-15-2007, 02:13 PM
Here is the where I got my original code fromhttp://members.aol.com/paypalcart/index1.html