Passing Variable from page to link

Discussion in 'Javascript' started by CHouck, Dec 20, 2004.

  1. CHouck

    CHouck Guest

    I have what seems to be a simple problem but I can't figure it out.

    I have a page where I have a link with variables built in which I want
    to pass through the URL so another page can pick the info up.

    My link on the first page (schedule.html) goes to this link:
    disclaimer.html?customer=238297&EventID=19080

    And I have some Javascript in the page which places the link info into
    the URL:

    <script language="JavaScript"><!--
    function nextpage(href,string) {
    location.href = href + '?' + string;
    }
    </script>

    Now on the (disclaimer.html) page I want to receive the info in the URL
    and then have a link that says "I Agree" that contains that dynamic
    info. So the link would look something like this:
    paymentpage.aspx?CustomerId=238297EventID=1908

    The problem is I have a no idea how to GET this info into the link.

    Any help anyone could give me would be greatly appreciated.
    Thanks,
    CHouck
     
    CHouck, Dec 20, 2004
    #1
    1. Advertising

  2. CHouck

    Guest

    hi,

    you need server side code , do you have access to server ? what
    languages are available?
    parameter passed to a html document via get or post are avalable on
    server side only.

    if you don't have access to the server , you may want to consider
    including or building the next html
    thanks
    Michael
     
    , Dec 20, 2004
    #2
    1. Advertising

  3. CHouck

    McKirahan Guest

    "CHouck" <> wrote in message
    news:...
    > I have what seems to be a simple problem but I can't figure it out.
    >
    > I have a page where I have a link with variables built in which I want
    > to pass through the URL so another page can pick the info up.
    >
    > My link on the first page (schedule.html) goes to this link:
    > disclaimer.html?customer=238297&EventID=19080
    >
    > And I have some Javascript in the page which places the link info into
    > the URL:
    >
    > <script language="JavaScript"><!--
    > function nextpage(href,string) {
    > location.href = href + '?' + string;
    > }
    > </script>
    >
    > Now on the (disclaimer.html) page I want to receive the info in the URL
    > and then have a link that says "I Agree" that contains that dynamic
    > info. So the link would look something like this:
    > paymentpage.aspx?CustomerId=238297EventID=1908
    >
    > The problem is I have a no idea how to GET this info into the link.
    >
    > Any help anyone could give me would be greatly appreciated.
    > Thanks,
    > CHouck
    >


    Will this work for you? Watch for word.wrap.

    <html>
    <head>
    <title>disclaimer.html</title>
    <script type="text/javascript">
    var qstr = location.search;
    qstr = qstr.replace(/\?/g,"&");
    var pair = qstr.split("&");
    var valu = new Array("","");
    for (var i=1; i<pair.length; i++) {
    var parm = pair.split("=");
    if (parm[0] = "customer") valu[0] = parm[1];
    if (parm[0] = "EventID") valu[1] = parm[1];
    }
    var page = "paymentpage.aspx"
    page += "?CustomerId=" + valu[0];
    page += "&EventID=" + valu[1];
    function nextpage() {
    location.href = page;
    }
    </script>
    </head>
    <body>
    <a href="javascript:nextpage()">I agree</a>
    </body>
    </html>


    Also, if your calling link looks like

    <a
    href="javascript:nextpage('http://www/','disclaimer.html?customer=238297&Eve
    ntID=19080')">link</a>

    why not remove the function by changing it to

    <a href="http://www/disclaimer.html?customer=238297&EventID=19080">link</a>
     
    McKirahan, Dec 20, 2004
    #3
  4. CHouck

    McKirahan Guest

    <> wrote in message
    news:...
    > hi,
    >
    > you need server side code , do you have access to server ? what
    > languages are available?
    > parameter passed to a html document via get or post are avalable on
    > server side only.


    Not true. You can access the querystring via location.search on the
    client-side.

    > if you don't have access to the server , you may want to consider
    > including or building the next html
    > thanks
    > Michael
    >
     
    McKirahan, Dec 20, 2004
    #4
  5. CHouck

    Börni Guest

    CHouck wrote:
    > I have what seems to be a simple problem but I can't figure it out.
    >
    > I have a page where I have a link with variables built in which I want
    > to pass through the URL so another page can pick the info up.
    >
    > My link on the first page (schedule.html) goes to this link:
    > disclaimer.html?customer=238297&EventID=19080
    >
    > And I have some Javascript in the page which places the link info into
    > the URL:
    >
    > <script language="JavaScript"><!--
    > function nextpage(href,string) {
    > location.href = href + '?' + string;
    > }
    > </script>
    >
    > Now on the (disclaimer.html) page I want to receive the info in the URL
    > and then have a link that says "I Agree" that contains that dynamic
    > info. So the link would look something like this:
    > paymentpage.aspx?CustomerId=238297EventID=1908
    >
    > The problem is I have a no idea how to GET this info into the link.
    >
    > Any help anyone could give me would be greatly appreciated.
    > Thanks,
    > CHouck
    >


    Hi,
    i hope i did unterstand right what you want, basically extracting GET
    information from the url.
    the following code snippet extracts everything after the first '=' in
    the url. with a bit of string manipulation you can modify it for your needs.
    And with a little DOM you can then modify the href attribute of the link
    after the page is loaded.

    if (window.location.search != "") {
    var text = window.location.search;
    var exempt =
    text.substring(location.search.indexOf("=")+1,location.search.length);
    }
     
    Börni, Dec 20, 2004
    #5
  6. CHouck

    CHouck Guest

    Thanks everyone for your help. I used McKirahan's (Thanks McKirahan)
    code and everything seems to be working Ok the only thing I 'm having
    problems with now is that when I click on the link that uses
    nextpage(), the URL is passing the EventID to both string parameters.
    So both CustomerID and EventID have the EventId in them. Any ideas...
    Thanks again,
    CHouck
     
    CHouck, Dec 21, 2004
    #6
  7. CHouck

    McKirahan Guest

    "CHouck" <> wrote in message
    news:...
    > Thanks everyone for your help. I used McKirahan's (Thanks McKirahan)
    > code and everything seems to be working Ok the only thing I 'm having
    > problems with now is that when I click on the link that uses
    > nextpage(), the URL is passing the EventID to both string parameters.
    > So both CustomerID and EventID have the EventId in them. Any ideas...
    > Thanks again,
    > CHouck
    >


    Show us your code, please.
     
    McKirahan, Dec 21, 2004
    #7
  8. CHouck

    McKirahan Guest

    "CHouck" <> wrote in message
    news:...
    > I have what seems to be a simple problem but I can't figure it out.
    >
    > I have a page where I have a link with variables built in which I want
    > to pass through the URL so another page can pick the info up.
    >
    > My link on the first page (schedule.html) goes to this link:
    > disclaimer.html?customer=238297&EventID=19080
    >
    > And I have some Javascript in the page which places the link info into
    > the URL:
    >
    > <script language="JavaScript"><!--
    > function nextpage(href,string) {
    > location.href = href + '?' + string;
    > }
    > </script>
    >
    > Now on the (disclaimer.html) page I want to receive the info in the URL
    > and then have a link that says "I Agree" that contains that dynamic
    > info. So the link would look something like this:
    > paymentpage.aspx?CustomerId=238297EventID=1908
    >
    > The problem is I have a no idea how to GET this info into the link.
    >
    > Any help anyone could give me would be greatly appreciated.
    > Thanks,
    > CHouck
    >


    Do the QueryString "names" ("customer" versus "CustomerId") have to be
    different between the two pages?

    disclaimer.html?customer=238297&EventID=19080

    paymentpage.aspx?CustomerId=238297EventID=1908


    If they could be made the same then you could just pass on the entire
    QueryString:

    <html>
    <head>
    <title>disclaimer.html</title>
    <script type="text/javascript">
    function nextpage() {
    location.href = "paymentpage.aspx" + location.search;
    }
    </script>
    </head>
    <body>
    <a href="javascript:nextpage()">I agree</a>
    </body>
    </html>

    <a href="disclaimer.html?CustomerId=238297&EventID=19080">Disclaimer</a>
     
    McKirahan, Dec 21, 2004
    #8
  9. CHouck

    CHouck Guest

    You just answered my question...everything works great now.

    Thank you !!!

    CHouck

    BTW, the customer versus customerID thing was my screwup it was just
    supposed to be customerID for each page. My brains not running on all
    cylinders these days.
     
    CHouck, Dec 21, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    955
    Kevin Spencer
    May 17, 2005
  2. Steve
    Replies:
    2
    Views:
    539
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 1, 2007
  3. pereges
    Replies:
    7
    Views:
    463
    pereges
    Jun 1, 2008
  4. Carl Gilbert

    Link to run script and link to page

    Carl Gilbert, Jan 13, 2004, in forum: Javascript
    Replies:
    3
    Views:
    154
    Michael Winter
    Jan 13, 2004
  5. da
    Replies:
    2
    Views:
    111
Loading...

Share This Page