...

View Full Version : calling a value from a loop



conspiersacy
08-06-2006, 03: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. =)

vwphillips
08-06-2006, 03:32 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head>
<title></title>
<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=""/>');
}
}
</script>
</head>

<body>
<table cellpadding="0" cellspacing="1">
<tr>
<td colspan="1" class="floatleft">
<script type="text/javascript">
menu(6,'news','profile','gallery','commission','links','contact','','','','');
</script>
</td>
</tr>
</table>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum