$(document).ready(function() { $('.addcart_button').on('click', function(event) { event.preventDefault(); if ($('#product_shade').length && $('#product_shade').val() == '') { $('#addcart_result').addClass('error'); $('#addcart_result').html('

Please select a shade first

'); $('#addcart_result').fadeIn(); return false; } $('.addcart_button').val('Adding To Cart...'); var form_addtocart = $(this).closest('form'); $.post($(form_addtocart).attr('action'), $(form_addtocart).serialize(), function(data) { $('.addcart_button').val('Add To Cart'); $('#addcart_result').removeClass('error'); $('#addcart_result').html('

Product added to cart. View in basket or Checkout

'); $('#addcart_result').fadeIn(); }); }); $('#product_shade').change(function() { //if ($(this).val() == '') { return false; } var shade_class = ''; var the_product_id = $(this).val(); $('#add_product_id').val(the_product_id); if (the_product_id == 372) { shade_class = 'swatch-light'; } if (the_product_id == 373) { shade_class = 'swatch-medium'; } if (the_product_id == 374) { shade_class = 'swatch-tan'; } if (the_product_id == 375) { shade_class = 'swatch-dark'; } if (the_product_id == '') { shade_class = ''; } $('#product-swatch').attr('class',''); $('#product-swatch').addClass(shade_class); $('#addcart_result').fadeOut(); $('#addcart_result').html(''); return false; }); $('.swatch_select').click(function() { $('.swatch_select').each(function() { $(this).removeClass('selected'); }); $(this).addClass('selected'); var selected_swatch = $(this).attr('id'); var tmp_col = selected_swatch.split('-'); var selected_col = tmp_col[1]; $('.shade-desc p').hide(); $('#'+selected_col).show(); var the_product_id = ''; if (selected_col == 'light') { the_product_id = 372; } if (selected_col == 'medium') { the_product_id = 373; } if (selected_col == 'tan') { the_product_id = 374; } if (selected_col == 'dark') { the_product_id = 375; } /* $('#add_product_id').val(the_product_id); $('#product_shade > option').each(function() { if ($(this).val() == the_product_id) { $(this).attr('selected',true); } }); */ return false; }); });