Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Passing Variable from page to link

Reply
Thread Tools

Passing Variable from page to link

 
 
CHouck
Guest
Posts: n/a
 
      12-20-2004
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

 
Reply With Quote
 
 
 
 
mxa@yahoo.com
Guest
Posts: n/a
 
      12-20-2004
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

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      12-20-2004
"CHouck" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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[i].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">lin k</a>


 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      12-20-2004
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
Börni
Guest
Posts: n/a
 
      12-20-2004
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,loca tion.search.length);
}

 
Reply With Quote
 
CHouck
Guest
Posts: n/a
 
      12-21-2004
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

 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      12-21-2004
"CHouck" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.


 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      12-21-2004
"CHouck" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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=19 080">Disclaimer</a>


 
Reply With Quote
 
CHouck
Guest
Posts: n/a
 
      12-21-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variable between asp login page and the redirected page Steve ASP .Net 2 11-01-2007 11:32 AM
Passing text from variable in a link da Javascript 2 07-29-2007 10:39 PM
I want to create a link "e-mail this page to a friend" on clicking this link i want to send the URL of that current page to a friend pavi Javascript 0 01-13-2006 12:10 PM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM



Advertisments