jumpink
05-15-2007, 11:19 AM
Required field(s) validation
http://www.dynamicdrive.com/dynamicindex16/requiredcheck.htm
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.
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>
http://www.dynamicdrive.com/dynamicindex16/requiredcheck.htm
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.
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>