#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0

    Compare to Anything?


    I have 3 drop-down boxes where the user selects a value on my php page. Whenever a change is make I have it call the function srch().

    Each box initially starts with * which I intend to represent "everything".

    Is there a way in javascript during a string comparison to place a value so the comparison will pull anything?

    Age=30
    Sex=*
    Height=66 inches

    if (sex == "*")
    {
    val2=ANYTHING
    }
    else
    {
    val2=sex
    }

    if (val1 == 30 && val2 == ANYTHING && val3 == 66 inches)
    {
    //run code
    }
    else
    {
    //run code
    }

    Is there a value I can insert in place of the "*"/ANYTHING during my comparison so it won't filter anything on that comparison?

    I thought about using !== but then you still need to write a lot of if statements to compensate for every combination of "*" between the 3 drop-downs.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,932
    Rep Power
    4033
    No, there is no special anything value. What you need to do is create a condition which is always true when * is used. For example:


    Code:
    if (sex == '*' || sex == searchTerm){
    }
    if * is selected, that condition is always true, if anything else is selected, it compares it to searchTerm.

    Comments on this post

    • lilmark agrees
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    4
    Rep Power
    0
    Agh! It's so obvious now.

    Thanks man!

IMN logo majestic logo threadwatch logo seochat tools logo