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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Simple Counting Loop

    I am trying to get a script to generate a list of sequential URLs and display them in my browser. So far this is what I have come up with, but it does not work. I am sure there is something wrong with the two loops, but the error message doesn't help much. Thanks in advance!
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>http</title>
    <script language="javascript">
    <!--//
    
    function count(){
    	var x = 1;
    	var y = 1;
    	while(x < 100) x++ {
    		while(y < 100) y++ {
    			document.write('any url' + x + '/' + y + '.jpg<br />');
    		}
    	}
    }
    
    //-->
    </script>
    </head>
    
    <body>
    
    </body>
    
    </html>
    Thomas ><>

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, try this?
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>http</title>
    <script language="javascript">
    <!--//
    
    function count(){
     for(var x = 1; x < 100; x++) {
      for(var y = 1; y < 100; y++) {
       document.write('any url' + x + '/' + y + '.jpg<br />');
      }
     }
    }
    
    //-->
    </script>
    </head>
    
    <body>
     <script>count();</script>
    </body>
    
    </html>
    The x++ is just floating, it's not clear when it should be executed:
    Code:
    while(x < 100) x++ {
     ...
    }
    It should have been like this:
    Code:
    while(x < 100) {
     ...
     x++;
    }
    Also, you never called your count() method, so it would have never executed.

    Hope that helps,
    Sadiq.

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, that works perfectly! Is it possible to set the x and y limits with a dropdown text-entry box? Then I could call the script with a submit button or text.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well you'll have to pick one: drop-down box or text box -- not both!

    Either one is fine. Here's an example with the text box:
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>http</title>
    <script language="javascript">
    <!--//
    
    function count(){
     var x_limit = document.getElementById("x_limit").value*1;
     var y_limit = document.getElementById("y_limit").value*1;
     var countOutput = document.getElementById("countOutput");
    
     countOutput.innerHTML = "";
    
     for(var x = 1; x < x_limit; x++) {
      for(var y = 1; y < y_limit; y++) {
       countOutput.innerHTML += 'any url' + x + '/' + y + '.jpg<br />';
      }
     }
    }
    
    //-->
    </script>
    </head>
    
    <body>
     x limit: <input type="text" id="x_limit" /><br />
     y limit: <input type="text" id="y_limit" /><br />
     <button onClick="count();">count</button>
    
     <div id="countOutput"></div>
    </body>
    
    </html>
    I think that should work..

    Sadiq.


  •  

    Posting Permissions

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