...

View Full Version : Simple Counting Loop



TomFIng
04-23-2004, 07:40 PM
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!


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

sad69
04-23-2004, 07:54 PM
Okay, try this?


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


while(x < 100) x++ {
...
}


It should have been like this:


while(x < 100) {
...
x++;
}


Also, you never called your count() method, so it would have never executed.

Hope that helps,
Sadiq.

TomFIng
04-23-2004, 08:25 PM
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.

sad69
04-23-2004, 08:53 PM
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:


<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum