show layer onload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BGT

    show layer onload

    Hi

    I have some layers, at the same position.
    I want to show one of them according to the system language,
    and I have made this so far:

    function showit() {
    if (lang == "da") document.da.vis ibility="show"
    if (lang == "de") document.de.vis ibility="show"
    if (lang == "it") document.it.vis ibility="show"
    if (lang == "fr") document.fr.vis ibility="show"
    ............... ..

    <div class="box" id="da" style="visibili ty: hidden; position:
    absolute; top: 1500px; align: center;">
    <div class="box" id="de" style="visibili ty: hidden; position:
    absolute; top: 1500px; align: center;">
    ..... and so on .......

    body onload showit()

    But it get: 'document.da' is null or not an object

    What do I do wrong ?

  • Randy Webb

    #2
    Re: show layer onload

    BGT wrote:
    [color=blue]
    > Hi
    >
    > I have some layers, at the same position.
    > I want to show one of them according to the system language,[/color]

    How are you determining system language?
    [color=blue]
    > and I have made this so far:
    >
    > function showit() {
    > if (lang == "da") document.da.vis ibility="show"
    > if (lang == "de") document.de.vis ibility="show"
    > if (lang == "it") document.it.vis ibility="show"
    > if (lang == "fr") document.fr.vis ibility="show"
    > ............... ..[/color]



    document.getEle mentById('da'). style.visibilit y = "visible";
    And, where is lang defined?
    [color=blue]
    > <div class="box" id="da" style="visibili ty: hidden; position:
    > absolute; top: 1500px; align: center;">
    > <div class="box" id="de" style="visibili ty: hidden; position:
    > absolute; top: 1500px; align: center;">
    > ..... and so on .......[/color]

    If your visitors have JS disabled, they will see nothing. This whole
    project is better suited to be done on the server, or, to have static
    links on an intro page to each language page.
    [color=blue]
    > body onload showit()
    >
    > But it get: 'document.da' is null or not an object[/color]

    What browser?

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Richard

      #3
      Re: show layer onload

      Then why are we here discussing javascript at all if a very small percentage
      of users have it turned off?

      Have we not heard of "MAJORITY RULES"?
      I've seen a vast majority of sites using some form of JS.

      If you were to go to the country of Greece, you would expect everyone there
      to know and understand English.

      Why can't you just assist someone without the negativism all the time?


      Comment

      • BGT

        #4
        Re: show layer onload

        On Sun, 23 Jan 2005 19:48:52 -0500, Randy Webb
        <HikksNotAtHome @aol.com> wrote:
        [color=blue][color=green]
        > > I want to show one of them according to the system language,[/color]
        >
        > How are you determining system language?[/color]
        that is no problem, works perfect on all other pages.
        [color=blue]
        > document.getEle mentById('da'). style.visibilit y = "visible";
        > And, where is lang defined?[/color]
        lang is defined in another extern script.
        [color=blue]
        > If your visitors have JS disabled, they will see nothing. This whole
        > project is better suited to be done on the server, or, to have static
        > links on an intro page to each language page.[/color]
        Less than 1% of my visitors has js disabled,
        if js was a problem this group would probably not exist :)
        [color=blue][color=green]
        > > But it get: 'document.da' is null or not an object[/color]
        > What browser?[/color]
        IE6

        Comment

        • Duncan Booth

          #5
          Re: show layer onload

          BGT wrote:
          [color=blue]
          > I have some layers, at the same position.
          > I want to show one of them according to the system language,
          > and I have made this so far:
          >
          > function showit() {
          > if (lang == "da") document.da.vis ibility="show"
          > if (lang == "de") document.de.vis ibility="show"
          > if (lang == "it") document.it.vis ibility="show"
          > if (lang == "fr") document.fr.vis ibility="show"
          > ............... ..
          >
          ><div class="box" id="da" style="visibili ty: hidden; position:
          > absolute; top: 1500px; align: center;">
          ><div class="box" id="de" style="visibili ty: hidden; position:
          > absolute; top: 1500px; align: center;">
          > ..... and so on .......
          >
          > body onload showit()
          >
          > But it get: 'document.da' is null or not an object
          >
          > What do I do wrong ?
          >
          >[/color]

          A better way to do this would be to set a class on your body tag (or
          another tag enclosing all of the language specific sections). So for
          example, your HTML could contain:

          <body class="language-en">

          showit can modify the body class, and you then use css to control the
          visibility of whatever sections you want:

          function showit() {
          document.body.c lassName = "language-"+lang;
          }

          You may need to add some checking code if there is any chance lang is set
          to something unexpected.

          Also, you should move the position and alignment out of style attributes
          and into a stylesheet.

          Comment

          Working...