This example assumes you have a product option with a class of PaperColor and you want to make sure the field isn't left completely blank.
Quote:
if (product_option('PaperColor').value == '') {
alert('Paper Color must be chosen before adding to cart.');
return false;
}
|
The "return false;" statement stops X-Cart from adding the product to the cart.
You could also ask the user if the field is intentionally left blank using the following code:
Quote:
if (product_option('PaperColor').value == '') {
if (confirm('Add to cart with Paper Color blank?')) {
return true;
} else {
return false;
}}
|
The confirm is like an alert except it has "OK" and "CANCEL" buttons. If the user clicks "OK" the product will be added, if they click "CANCEL" it will not be added.
If you need any other JavaScript validation help let me know - I know JS like the back of my hand.
Al Ponte
agponte@infosolvllc.com