SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Looping Issue

  1. #1
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Looping Issue

    Code:
    <html>
    <head>
    <title>for jesse</title>
    <script language="javascript">
    <!--
    function makeTable()
    {
    // create table, define columns
    document.write('<table widtd="100%" border="0" cellpadding="3" cellspacing="2">');
    document.write("<tr><td>weight</td><td>normal</td><td>quick</td></tr>" );
    // set beginning variable to 
    var type="normal";
    for(i=1;i<15;++i)
    {
    window.alert(i);
    document.write("<tr>" );
    document.write("<td>" + i*100 + "</td>" );
    for(m=0;m<2;++m)
    {
    if(type=="normal" )
    {
    	document.write("<td>" + i*50 + "</td>" );
    	type="quick";
    }
    elseif(type=="quick" )
    {
    	document.write("<td>" + i*100 + "</td>" );
    	type="normal";
    }
    }
    document.write("</tr>" );
    window.alert(type);
    }
    document.write("</table>" );
    }
    // -->
    </script>
    </head>
    <body>
    <script language="javascript">
    makeTable();
    </script>
    </body>
    Why is the above not going through the second loop more than once? It just fails to continue after it goes through the inner loop once...

    Help?

    J
    Last edited by Jeremy W.; Mar 22, 2003 at 12:03.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I also tried it this way, but it wouldn't call the funcs...

    Code:
    <html>
    <head>
    <title>for jesse</title>
    <script language="javascript">
    <!--
    function makeTable()
    {
    createBits("top" ); // create table, define columns
    makeRows(); //make rows
    createBits("bottom" ); //close table
    }
    function createBits(bit)
    {
    if(bit=="top" )
    {
    document.write('<table widtd="100%" border="0" cellpadding="3" cellspacing="2">');
    document.write("<tr><td>weight</td><td>normal</td><td>quick</td></tr>" );
    }
    elseif(bit="bottom" )
    {
    document.write("</table>" ); 
    }
    }
    function makeRows()
    {
    for(i=1;i<15;++i)
    {
    document.write("<tr>" );
    document.write("<td>" + i*100 + "</td>" );
    document.write("<td>" + i*50 + "</td>" ); 
    document.write("<td>" + i*100 + "</td>" );
    document.write("</tr>" );
    }
    }
    // -->
    </script>
    </head>
    <body>
    <script language="javascript">
    makeTable();
    </script>
    </body>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just updated both code snippets to put the JS in the <head> ... silly me. Still doesn't work though.

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first one worked for me after changing 'elseif' to 'else if'.

  5. #5
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ahhh *LOL* ... Stupid ASP habits :hangs head in shame:

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL!

    Yeah, I do the same thing after I've been using VB.


Bookmarks

Posting Permissions

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