newbie; help with writing simple function

R

Rob

I'm developing a proof-reading page for a multi-language site. On my
proofing page, I would like the proof-reader to be able to click a "language
link" at the top of the page; forcing a page reload with paragraphs written
in the chosen language.

I've created a series of document.write statements which insert a variable
called "lango", thereby changing the pathname for the documents to be
written out, to a particular langague name; Example >>

document.write('<scr'+'ipt language="Javascript"
type="text/javascript"
src="languages/'+lango+'/paragraph1.js"></scr'+'ipt>');

I have a numbered series of about 20 or so paragraphs for proofing
(paragraph1.js, paragraph2.js.... etc). My script which currently assigns
the "lango" variable for these statements - which seems oddly enough to only
work when placed in the <body>, not the <head> of the document, is this:

<script language="JavaScript">
<!--
var lango = "en";
// -->
</script>


What I would like to do is write a function, whereby when a proofreader
clicks on a language link on the top of the page, it will re-assign the
variable "lango" to a string representing his chosen language and force a
page refresh with the new variable in force (or is that not possible without
cookies?)

So, a visitor clicks the french link at the top of the page.

The link looks like this: <a href="#" onClick="LangClick(fr)">FRENCH
VERSION</a>

The LangClick function looks something like this (forgive me if i'm way
off!)

<script language="JavaScript">
<!--
var lango = "en";
function LangClick(clicko)
{ var lango = var clicko;
document.location.reload();
}
// -->
</script>

I'm attempting to pass the argument " fr " to the function LangClick, in the
form of variable "clicko", which will then be assigned to variable "lango".
(I've used "lango" because "lang" is a reserved attrib for html tags)

thanks for any help with this; i don't normally use much JS in my pages,
just begining to experiment with it.

Rob
 
B

Benjamin

When you reload the page you'll loose all the varibles, so this is what
I suggest:
Here's the function:
function LangClick(clicko) {
//This reloads the page but still carries the language setting
location.href = "thispage.html?lango=" + clicko;
}
Then have something like this:
var query = location.search.substring(1).split("=")
document.write("<script type=\"text/javascript\" src\"languages\\" +
query[1] + "\\paragraph1.js");
That caputure the extra data on the end of the url and writes a script
tag.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top