Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dhtml troubles

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If I have the code below in my html header and the items in the array are all ids of this type: <div id=&quot;main><!-- Stuff --></div>
Why am I getting an error that says object expected when I try to call the function?

ar_menu=new Array(
&quot;main&quot;,
&quot;music&quot;,
&quot;media&quot;,
&quot;biography&quot;,
&quot;events&quot;,
&quot;press&quot;,
&quot;contacts&quot;,
)

var i;
var cur_item;
var pre_item = 0;

function posMenu () {
for (i=0; i<ar_menu.length; i++) {
cur_item = document.getElementById(ar_menu);
cur_item.style.top = pre_item+20+&quot;px&quot;;
pre_item = pre_item+20;
}
}
 
an array is not a document element, so you can't use getElementById on it.

nick bulka

 
TGML prevented the from being displayed and italicized the remainder of your script (i think) so I will assume you meant to have it there...

I tried this:

<div id=&quot;main&quot; style=&quot;width:100px;height:20px;background-color:red;position:absolute;&quot;></div>
<div id=&quot;music&quot; style=&quot;width:100px;height:20px;background-color:green;position:absolute;&quot;></div>

<script>
ar_menu=new Array(
&quot;main&quot;,
&quot;music&quot;
)

var i;
var cur_item;
var pre_item = 0;

function posMenu () {
for (i=0; i<ar_menu.length; i++) {
cur_item = document.getElementById(ar_menu);
cur_item.style.top = pre_item+20+&quot;px&quot;;
pre_item = pre_item+20;
}
}
posMenu()
</script>

and it worked fine...maybee you didn't create one of the items in the array... jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top