using javascript with the DOM

T

test

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.display = '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.display = 'none';

is there a way to do this?
something like
document.bio{bioId}.display = 'none';
 
L

Lasse Reichstein Nielsen

test said:
i have a function that has a number passed to it
the variable is called "bioId" ....
so lets say I pass a 3
i want that statement to say

document.bio3.display = 'none';

First of all, you should not write
document.bio3
to refer to an element with name "bio3". The proper way would
be
document.getElementById("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.getElementById("bio"+bioId).style.display="none";
(or
document.images["bio"+bioId].style.display = "none";
is there a way to do this?
something like
document.bio{bioId}.display = 'none';

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

/L
 
D

Dag Sunde

test said:
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.display = '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.display = 'none';

is there a way to do this?
something like
document.bio{bioId}.display = 'none';

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

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top