Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    How do you get variables from the URL?
    like
    page.htm?pg=test

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    You will need a server side language to do this - ASP, PHP etc. I believe it can be done in Javascript but it would be a pain in the arse.
    JR

  4. #3
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    hrm I guess so... but how bout just like

    page.htm?test

    would that work?

  5. #4
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I've used this in the past...

    Code:
    <script>
    if (location.search) {
     ref = location.search.slice(1); // stores everything after the "?"
     val = ref.split("="); // splits the var=val into an array (0=>'"var",1=>"val")
     alert(val[1]);
    }
    </script>
    Just replace the line alert(val[1]); with whatever you want to do with the variable.
    An example would be:
    http://www.yourdomain.com/somePage.html?pg=left
    This script used at this url would alert "left".

    You could also do it with just the value by omiting a few lines, like so:

    Code:
    <script>
    if (location.search) {
     ref = loaction.search.slice(1);
     alert(ref);
    }
    </script>
    Again replace the alert line with what you would do with the variable.
    This time using your last exaple, it would alert "test"
    Good Luck.
    - Brian

  6. #5
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    thanks alot man that really helps and it really works

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Here is how to do it in PHP if you need it...

    http://www.webdesignforums.net/thread9737.html
    JR


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:45 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com