View Full Version : calling a value from a loop

08-06-2006, 04:11 PM
i am designing a function that will generate a menu to be used across several websites. the code i have developed goes through all of the motion i want it to, except for one quirk: while in the loop, instead of going through the loop and inserting choice1, choice2, et cetera i want it to insert, in this example, news, profile, et cetera.

this is the call to the function:

<tr><td colspan="3" class="floatleft"><script type="text/javascript">menu(6,'news','profile','gallery','commission','links','contact','','','','');</script></td></tr>

this is the function itself:

function menu(choices, choice1, choice2, choice3, choice4, choice5, choice6, choice7, choice8, choice9, choice10)
document.write('<img src="menuspace_0.png" alt=""/>')
counter = 1;
while(counter <= choices)
document.write('<img class="link" src="menu_'+['choice'+counter]+'.png" alt="" onmouseover="this.src=\'menu_'+['choice'+counter]+'_h.png\';" onmouseout="this.src=\'menu_'+['choice'+counter]+'.png\';" onclick="changecontent(\''+['choice'+counter]+'\');"/>')
document.write('<img src="menuspace_'+counter+'.png" alt=""/>');
counter = counter + 1;

thanks in advance -- this is my first post. i hope i made myself clear. =)

08-06-2006, 04:32 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script type="text/javascript">
function menu(){
var args= menu.arguments;
document.write('<img src="menuspace_0.png" alt=""/>')
for (i=1;i<args[0];i++) {
document.write('<img class="link" src="menu_'+args[i]+i+'.png" alt="" onmouseover="this.src=\'menu_'+args[i]+i+'_h.png\';" onmouseout="this.src=\'menu_'+args[i]+i+'.png\';" onclick="changecontent(\''+args[i]+i+'\');"/>')
document.write('<img src="menuspace_'+i+'.png" alt=""/>');

<table cellpadding="0" cellspacing="1">
<td colspan="1" class="floatleft">
<script type="text/javascript">