View Single Post
  #17  
Old 06-04-2004, 09:55 PM
 
Adian009 Adian009 is offline
 

Advanced Member
  
Join Date: Mar 2004
Location: Tiverton, RI, USA
Posts: 37
 

Default How to Validate a Text Entry Field / Product Option

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
__________________
---------------------------------------------
Infosolv, LLC
A Professional Services Company
X-Cart v3.5.10 & 4.01
Find our MOD\'s at: Custom X-Cart MOD\'s, Add-On\'s & X-Cart Hosting!
Reply With Quote