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
    Jul 2012
    Location
    Edinburgh UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing URL param to Javascript

    Hi, I'm sure this is a simple one, but I can't find a simple answer anywhere.

    I have a webpage that calls a javascript calendar and one of the parms passed is how many months to display. What I want to do is pass a parm on the URL to set the number of months to display. I cant figure out how to pass the parm value to the parm value needed by javascript. e.g.

    [ICODE]<script language="javascript" src="/calendar/load.php?view=3&cid=1"></script>[ICODE]

    view = number of months to display.

    I want to be able to have ?view=myparmvaluefromURL

    I cant get the page to resolve the value for myparmvaluefromURL and pass to ?view parm.

    Any help appreciated. At the moment I just have multiple pages with the values for 3,6,9 and 12 hardcoded - but means I have 4 pages to maintain when updating.

    Thanks.
    Last edited by macleda; 07-17-2012 at 10:20 AM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You can use document.URL to get the URL, then split the URL several times.

    First split on ? which will give you the URL as position 0, then the params as position 1 of the array (or the object that can be treated like an array.) Then split on & to get each name/value pair, then split each on = to get the name and value.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,200
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    Ummm...I could be wrong, but I *THINK* that what he means is that he wants the PHP page to receive those parameters, AS IS:
    /calendar/load.php?view=3&cid=1

    But then he wants the JAVASCRIPT as generated by the PHP code to see a *DIFFERENT* set of parameters.

    There's no simple way to do that.

    BUT...

    But it's trivial to pass a value from PHP to the JavaScript of a page:
    Code:
    <script type="text/javascript">
    var anyName = "<?php echo $somePhpVariable; ?>";
    ...
    </script>
    So WHY would you want to try to get the parameters from the URL when you can pass stuff in from PHP code so easily?

    If I have completely misunderstood, maybe an example from macleda would help?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Edinburgh UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Old Pedant

    I think maybe I didn't explain properly. It is PHP script that should receive the variable (hopefully from HTML parms when I call the page). I have no access to the PHP as it's 3rd party calendar protected by ZEND.

    If you look at my live page you will see how I am handling option to display 3,6,9 or 12 month calendar.

    http://www.trotternishridgeviewcotta...uk/tariff.html

    What I can't figure is how to get HTML param value resolved into the variable passed to the PHP.

  • #5
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Edinburgh UK
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Wolfshade, unfortunately, I don't have access to the PHP that uses the parameter passed, so need to be able to pass from the calling page - if possible.


  •  

    Tags for this Thread

    Posting Permissions

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