newbie; help with writing simple function

Discussion in 'Javascript' started by Rob, Sep 10, 2006.

  1. Rob

    Rob Guest

    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
    Rob, Sep 10, 2006
    #1
    1. Advertising

  2. Rob

    Benjamin Guest

    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
    Benjamin, Sep 10, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,399
    HNguyen
    Dec 21, 2004
  2. Stef Mientki
    Replies:
    8
    Views:
    272
    Stef Mientki
    Dec 28, 2006
  3. drew
    Replies:
    6
    Views:
    174
  4. spazzwig
    Replies:
    3
    Views:
    104
    spazzwig
    Aug 25, 2003
  5. Richard A. DeVenezia

    Function writing function

    Richard A. DeVenezia, Apr 3, 2004, in forum: Javascript
    Replies:
    3
    Views:
    94
    Lasse Reichstein Nielsen
    Apr 5, 2004
Loading...

Share This Page