开发者

jquery issue involving dropdown menu

开发者 https://www.devze.com 2023-03-04 14:47 出处:网络
Here is my situation I\'m using zen-cart for e-comm site. In product details page there are products attributed like color and size both are in drop down menu.

Here is my situation I'm using zen-cart for e-comm site.

In product details page there are products attributed like color and size both are in drop down menu.

The requirement was when a shopper clicks "add to cart" with out selecting the attributes a alert saying select color this goes for the size also.

My problem when I click "add to cart" the alert box appears after I close the box and click "add to cart" without selecting the attributes nothing happens.

This is jQuery coding

 //#attrib-Size is the id for Size attribute
 //#attrib-Color is the id for Color attribute  


$("#attrib-Size").change(function(){
 $("#for_alert").val(1);
});

$("#attrib-Color").change(function(){ 
 $("#for_alert").val(1);
});

/*Add to cart */                
$(".des_buynow_addcart").click(function(){
 if($("#for_alert").val() == 1){
  $("#for_alert").val(0);       
  if($("#attrib-Size").val() == 0){
   alert ("PLEASE SELECT SIZE");
   return f开发者_StackOverflowalse;
  }
  else if($("#attrib-Color").val() == 0){
   alert ("PLEASE SELECT COLOR");
   return false;
   }
  else{

This is HTML coding

<input class="des_buynow_addcart" type="image" src="includes/templates/********/buttons/english/addto-cart.png" alt="Add to Cart" title=" Add to Cart "/><br/>

<input type="hidden" value="1" name="for_alert" id="for_alert"/>


It's this part:

if($("#for_alert").val() == 1){
  $("#for_alert").val(0);      

If the value is 1, you then set it to 0. Now if you click the button again, the value will be 0 so it's going to skip the if all together.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号