Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:10:19+00:00 2026-05-31T17:10:19+00:00

Trying to setup some validation on the add to cart button for the dropdown

  • 0

Trying to setup some validation on the add to cart button for the dropdown selections for size and color on my simplecart shelf items on my wordpress site. I can get the alert to pop and block the adding of the item, but it is wrong because the alert pops even with the proper values selected. I have been searching this for days now and have found a couple people asking the same question with no response, so any input on how and if this is possible would be amazing.

Here is the add to cart function:

me.add = function () {
    var me=this;
    /* load cart values if not already loaded */
    if( !me.pageIsReady     ) { 
        me.initializeView(); 
        me.update();    
    }
    if( !me.isLoaded        ) { 
        me.load(); 
        me.update();    
    }

    var newItem = new CartItem();

    /* check to ensure arguments have been passed in */
    if( !arguments || arguments.length === 0 ){
        error( 'No values passed for item.');
        return;
    }
    var argumentArray = arguments;
    if( arguments[0] && typeof( arguments[0] ) != 'string' && typeof( arguments[0] ) != 'number'  ){ 
        argumentArray = arguments[0]; 
    } 

    newItem.parseValuesFromArray( argumentArray );
    newItem.checkQuantityAndPrice();

The code I am trying to implement:

if( item_Size = "none" ){
        alert("Please select a size");
        return;
    }


if( item_Color = "none" ){
        alert("Please select a color");
        return;
    }

Now Im a noob when it comes to this stuff so Im not even sure where it stores the values so it could be any setting variable name and the code could be completely wrong but none is the value of the default select option.

This is how it loads and saves the cookies:

me.load = function () {
    var me = this;
    /* initialize variables and items array */
    me.items = {};
    me.total = 0.00;
    me.quantity = 0;

    /* retrieve item data from cookie */
    if( readCookie('simpleCart') ){
        var data = unescape(readCookie('simpleCart')).split('++');
        for(var x=0, xlen=data.length;x<xlen;x++){

            var info = data[x].split('||');
            var newItem = new CartItem();

            if( newItem.parseValuesFromArray( info ) ){
                newItem.checkQuantityAndPrice();
                /* store the new item in the cart */
                me.items[newItem.id] = newItem;
            }
        }
    }
    me.isLoaded = true;
};



/* save cart to cookie */
me.save = function () {
    var dataString = "";
    for( var item in this.items ){
        dataString = dataString + "++" + this.items[item].print();
    }
    createCookie('simpleCart', dataString.substring( 2 ), 30 );
};

The full simpleCart code can be found here:simplecartjs.com

Any help would be greatly appreciated, I have tried other form validation techniques but am having trouble using anything meant for post validation because of the way simplecart stores variables. PLEASE HELP!!

Thank you for you time and efforts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:10:21+00:00Added an answer on May 31, 2026 at 5:10 pm

    In the code you are trying to implement, you are assigning the value of “none” to the variable “item_size”. Since it will be true, the popup will show. You want to use two “=” when performing a comparison.

    Your code:

    if( item_Size = "none" )
    

    Fixed:

    if( item_Size == "none" )
    

    At first glance that should fix the problem. Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get some validation setup for one of my ORM models. I
I'm trying to setup some caching on my site and am having troubles with
I'm trying to setup some friendly URLs on a SharePoint website. I know that
I am trying to setup some decorators so that I can do something like:
Trying to setup an SSH server on Windows Server 2003. What are some good
I am trying to setup a few fixes in some code that have caught
I'm trying to setup VIM for editing Actionscript 3 for some upcoming Flash projects.
I'm trying to find some information on preferred solution setup when using MVC 2
I am trying to render video via the NDK, to add some features that
I'm trying to figure out the best way to setup some tables in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.