Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile Reach IF statment from address field

    Hi!
    Is there any way to reach a IF ELSE statment via the address filed?

    Like there is with the GET method for PHP?

    For example index.html?car=mercedes writes or reqiure a file, that should have been viewed if the variable cars value was "mercedes"?

    / Vilhelm

  2. #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,576
    Thanks
    58
    Thanked 649 Times in 644 Posts
    you can check the value of the query string like this:
    Code:
    var car=window.location.search.substring(1).split("=")[1];
    if (car=="mercedes"){
    alert("do stuff")
    }
    ... the "do stuff" bit I leave to you...

  3. #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Allowing for missing parameter:
    Code:
    var car=window.location.search.substring(1).split("=");
    
    if ( car.length == 2 && car[ 1 ] == "mercedes" )
    {
      alert("do stuff")
    }

  4. #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,576
    Thanks
    58
    Thanked 649 Times in 644 Posts
    fair enough. seems overly cautious though... if the string is index.html?car=

    then window.location.search.substring(1).split("=")[1]

    will return blank, which obviously != "mercedes", so why?

  5. #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by xelawho View Post
    fair enough. seems overly cautious though... if the string is index.html?car=

    then window.location.search.substring(1).split("=")[1]

    will return blank, which obviously != "mercedes", so why?
    I just don't like to see the practice of assuming the existence of an object or element, even if it's not fatal.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •