Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > newbie; help with writing simple function

Reply
Thread Tools

newbie; help with writing simple function

 
 
Rob
Guest
Posts: n/a
 
      09-10-2006

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


 
Reply With Quote
 
 
 
 
Benjamin
Guest
Posts: n/a
 
      09-10-2006
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.
Rob wrote:
> 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


 
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
Split function and parsing for writing as hyperlink; help please CompleteNewb@comcast.net ASP General 0 08-13-2009 05:46 PM
Help writing function please, tonyjeffs@aol.com C++ 6 05-07-2005 03:11 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Function writing function Richard A. DeVenezia Javascript 3 04-04-2004 11:58 PM



Advertisments