Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing same variable through url

Status
Not open for further replies.

GiddyRob

Programmer
Aug 25, 2005
37
GB
Hi, Im putting together a site and I want to know how to pass a variable across the url that already has a value. The reason for this is that the site is for visually impaired people so it has a selection of four different text sizes. I have a javascript variable called font and I want to pass the value of that around the site through the url when the user presses any href links. This is so that the text stays the size set by the user and doesnt go back to the normal size ie 100%.

Code:
<div id="topnav_box"><H2 class="navtextbold">
			<div class="topnav_latest_news" align="center"><a href="../latest_news/index.html?font=$font">&nbsp;Latest&nbsp;News&nbsp;</a></div>
			<div id="topnav_spacer"></div>
			<div id="topnav_about_us" align="center">&nbsp;About&nbsp;Us&nbsp;</div>
			<div id="topnav_spacer"></div>
			<div id="topnav_pals" align="center">&nbsp;PALS&nbsp;</div>
			<div id="topnav_spacer"></div>
			<div id="topnav_rec" align="center">&nbsp;Recruitment&nbsp;</div>
			<div id="topnav_spacer"></div>
			<div id="topnav_questions" align="center">&nbsp;Your&nbsp;Questions&nbsp;</div>
			<div id="topnav_spacer"></div>
			<div id="topnav_patient" align="center">&nbsp;Patient&nbsp;Information&nbsp;</div>
			<div id="topnav_spacer"></div>
			<div id="topnav_vis" align="center">&nbsp;Visitor&nbsp;Information&nbsp;</div></H2>
		</div>

I know the code above doesnt work but it is included to help show what i am trying to do. I usually do stuff like this in PHP so am a little unclear how to acheive this using Javascript.

I basically want to make font = the value of font which already has a value.

Any help would be very much appreciated.

Regards

Rob :)
 
You'd be better off saving the value in a cookie and then have every page read the cookie and process the information appropriately. What you asked is possible, but would mean forcing each link to be processed through a Javascript function that would add the font to the URL before going to the page.

Lee
 
Look into using a cookie instead maybe? Then you can just read the value of the cookie whilst you are on any page - and not have to worry about passing stuff around like that.

Just an idea.

There are plenty of "pre-wrapped" cookie read/write scripts out there... it should be a breeze to check it out.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
And you could read the cookie with PHP and work with the information in a language you're more comfortable with then.

Lee
 
hmmm, i cannot use php so that is out of the window really. Is there any way of doing what I described above? I would like to avoid using cookies if possible.

Cheers

Rob
 
Why do you want to not use cookies? That would be the easiest way to get done what you want.

Lee
 
If you want to avoid cookies, you can just append
Code:
 &font=[i]value[/i]
to the URL. On entry to your page (I usually put it in an included file) on the server, get the value back from the request with
Code:
 var font = Request("font");
(you should wrap it in code to make sure that the value has been submitted).

Or you could use a session variable, but I think that might be the same as a cookie.

HTH
 
Thanks for your answer but I am a little unclear what you mean. I am having trouble doing it cos I can't use php but I don't want to use cookies. I would normally use php to do this. when the page is loaded font has a value but I need it to keep its value on every page accessed. In php I can just do:

Code:
...?font=$font

Is there a way to do a document.write to make the value of font = font?

Cheers

Rob
 
Show the code you already have for the URLs so we can see how to add what you want. Also, show your function for initially adding the font size to the URL of the links on the page so we can see what we're working with.

You haven't answered my question why you don't want to use cookies. That would be the most practical way of handling this.

Lee
 
Sorry - two conversations going on here. Lee - I guess the usual reason for not using cookies is that they might be disabled on the client. Rob - I assumed that you were referring to server-side javascript, so would set the font attributes there, perhaps through a CSS style, not on the client side. So if in your server script you are writing an href like this:

Code:
 Response.Write("<a href=//url1?arg1=val1&arg2=val2> tag </a>");
just alter it to

Code:
 Response.Write("<a href=//url1?arg1=val1&arg2=val2 &font=val> tag </a>");
So that the value you want to carry over to the next page is included in the link. That value will then appear in the QueryString of the Request on page url1 so you can use it to set the font attributes you want.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top