Page 1 of 1

i++ and showing the value on innerHTML

Posted: Tue Mar 03, 2009 8:31 am
by lovelf
Hello, I have the code below which writes the values but how to assign them to an id with innerHTML?

Code: Select all

<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
I tried:

Code: Select all

<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
document.getElementById("anyId").innerHTML = i + "<br>";
}
</script>
<span id="anyId"></span>
</body>
</html>
But it did not work :?

Re: i++ and showing the value on innerHTML

Posted: Tue Mar 03, 2009 8:47 am
by papa

Code: Select all

 
<span id='anyId'></span>
 
<script type="text/javascript">
var i_list = '';
for (var i=0;i<=10;i++)
 {
     i_list += 'The number is: ' + i + '<br />';
 }
document.getElementById("anyId").innerHTML = i_list;
</script>
 
Something like that ?

Re: i++ and showing the value on innerHTML

Posted: Wed Mar 04, 2009 7:41 am
by lovelf
Yes. Thanks papa.

Now, I am trying to store variables depending on the value of i, x times. x amount of variables.

Code: Select all

 
<span id='istart'></span>
<span id='istartb'></span>
<script type="text/javascript">
var i_list = '';
var cac = '5';
var pich = '.png';
for (var i=0;i<=cac;i++)
 {
i_listb = i + '' + pich +'';
     i_list += i + '' + pich +'';
}
var lala = i_list;
var lalab = i_listb;
document.getElementById("istart").innerHTML = lala;
document.getElementById("istartb").innerHTML = lalab;
</script>
 
I am trying to do a slide show in which I can set the number of images there will be displayed in variable cac.

I would want to store x amount of variables depending cac's value.

Code: Select all

i_listb = i + '' + pich +'';
gives me all numbers sequentially.

while code:

Code: Select all

i_listb = i + '' + pich +'';
outputs the last number.

Now, how could I get each number as a var?

var1, var2, and so on.