using javascript with the DOM

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

    using javascript with the DOM

    hello, i have a question on using javascript with the DOM
    can anyone help me out
    i have a function that has a number passed to it
    the variable is called "bioId"

    function visible(bioId);

    this number ranges between 1 and 6
    there is a statement in the function

    document.bio.di splay = 'none';

    i want the statement to change depending on what number i pass to the
    function
    so lets say I pass a 3
    i want that statement to say

    document.bio3.d isplay = 'none';

    is there a way to do this?
    something like
    document.bio{bi oId}.display = 'none';
  • Lasse Reichstein Nielsen

    #2
    Re: using javascript with the DOM

    test <test@test.co m> writes:
    [color=blue]
    > i have a function that has a number passed to it
    > the variable is called "bioId"[/color]
    ....[color=blue]
    > so lets say I pass a 3
    > i want that statement to say
    >
    > document.bio3.d isplay = 'none';[/color]

    First of all, you should not write
    document.bio3
    to refer to an element with name "bio3". The proper way would
    be
    document.getEle mentById("bio3" )
    possibly with fallbacks for old browsers.
    <URL:http://jibbering.com/faq/#FAQ4_41>

    If the element is a form or image, you can use the collections
    instead:
    document.forms['bio3']
    or
    document.images['bio3']

    Second, elements don't usually have a display property. It seems your
    code was written for Netscape 4, and it probably won't work very well
    anywhere else. The correct display property is in the style object.

    That answers the question:
    document.getEle mentById("bio"+ bioId).style.di splay="none";
    (or
    document.images["bio"+bioId].style.display = "none";
    [color=blue]
    > is there a way to do this?
    > something like
    > document.bio{bi oId}.display = 'none';[/color]

    This FAQ entry is close:
    <URL:http://jibbering.com/faq/#FAQ4_39>

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Dag Sunde

      #3
      Re: using javascript with the DOM

      "test" <test@test.co m> wrote in message
      news:0404200400 01511853%test@t est.com...[color=blue]
      > hello, i have a question on using javascript with the DOM
      > can anyone help me out
      > i have a function that has a number passed to it
      > the variable is called "bioId"
      >
      > function visible(bioId);
      >
      > this number ranges between 1 and 6
      > there is a statement in the function
      >
      > document.bio.di splay = 'none';
      >
      > i want the statement to change depending on what number i pass to the
      > function
      > so lets say I pass a 3
      > i want that statement to say
      >
      > document.bio3.d isplay = 'none';
      >
      > is there a way to do this?
      > something like
      > document.bio{bi oId}.display = 'none';[/color]

      document.getEle mentById("bio" + bioId).display = 'none';

      --
      Dag.


      Comment

      Working...