HighDots Forums  

using javascript with the DOM

Javascript JavaScript language (comp.lang.javascript)


Discuss using javascript with the DOM in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
test
 
Posts: n/a

Default using javascript with the DOM - 04-04-2004 , 12:04 AM






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';

Reply With Quote
  #2  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: using javascript with the DOM - 04-04-2004 , 10:40 AM






test <test (AT) test (DOT) com> writes:

Quote:
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";

Quote:
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
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #3  
Old   
Dag Sunde
 
Posts: n/a

Default Re: using javascript with the DOM - 04-04-2004 , 11:27 AM



"test" <test (AT) test (DOT) com> wrote

Quote:
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';

--
Dag.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.