Click to See Complete Forum and Search --> : script variable trouble


role
07-22-2003, 10:08 AM
why this one always alert 10???
i want it to alert from 1-10.... *this is only test*

for (abc=0;abc < 10;abc++) {
document.write('<span onclick="alert(abc)">counting</span><br />');
}

pyro
07-22-2003, 10:14 AM
Just a little quotes problem... try this:

<script type="text/javascript">
for (abc=0;abc < 10;abc++) {
document.write('<span onclick="alert('+abc+')">counting</span><br />');
}
</script>

sumyounguy
07-22-2003, 10:17 AM
actually, i think the problem is that in your for loops the document.write is overwriting itself, try document.writeln instead

pyro
07-22-2003, 10:19 AM
Nope, that's not the problem. My code works fine.

sumyounguy
07-22-2003, 10:19 AM
Pyro is right too though, make sure you put in your single quotes

sumyounguy
07-22-2003, 10:21 AM
really? nevermind then

role
07-23-2003, 11:12 AM
wow thank you very much!!
how stupid am i :D