Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calling a value from a loop

    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:

    Code:
    <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:

    Code:
    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. =)

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •