/    Sign up×
Community /Pin to ProfileBookmark

how to keep value of a variable?

hello,

I try to implement a multilanguage system to my website, but don’t know how to keep the value of a variable ( lang ) during website surfing. If I could do that, the rest is easy. Do you have any ideas? I don’t want to use sessions.
Thankx!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Aug 13.2005 — Either you need to use session variable on a server side language, a cookie, or a query string.

Eric
Copy linkTweet thisAlerts:
@xybooxauthorAug 13.2005 — the query string you've mentioned is reffering to database related solution?

isn't there any solution using javascript?
Copy linkTweet thisAlerts:
@A1ien51Aug 13.2005 — JavaScript is stateless, you can not keep a value in memory so you need to use a cookie or append the data you want to pass from page to page as a query string.

Eric
Copy linkTweet thisAlerts:
@qznAug 14.2005 — its quite possible in javascript

by querystring they mean passing something with a key-value pair

say you have a text box on your first page called username

if you pass something with a querystring you send username=whatwastypedin to the next page in the top of the browsers address

then on that second page you can "pick up" that list of values that were passed and reuse them

basically you just keep passing the info from place to place since you arent holding a session variable
Copy linkTweet thisAlerts:
@DarkRedSpiralAug 14.2005 — xyboox

Just a thought if your pages have forms that are being passed back and forth to your server why not use a hidden field to store the data rather than a JS variable. This will naturally be posted each time the form is processed.

<input type='hidden' id='lang' name='lang' value="English">

Your JS code could then change the value of this dependant on whatever method you have for the user to choose their language. After the initial POST of the data,each time you build your HTML that is returned simply recreate this field with POST data for field "lang' from the previous submission.

To access it in JS thereafter simply use the usual methods for accessing form elements.

Regards

Steve
×

Success!

Help @xyboox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...