There are several issues with the tiny piece of code you've supplied...
- javascript is case sensitive, therefore
I
and i
are different variables
- looping from 0 to i<=salesitems.length will end in an error, because if length is 10 and you use salesitem[10] it will fail (arrays are 0-based, and therefore an array with length of 10 has items 0 to 9)
- I believe you think that
salesitem[I]
will process like PHP, it won't. PHP allows you to use echo "print this $varName"
, javascript simply doesn't allow that.
Try something along these lines...
for (i = 0; i < salesitem.length; i++) {
document.write('<tr><td>' + salesitem[i] + '</td></tr>');
}
for (i = salesitem.length; i < 10; i++) {
document.write('<tr><td></td></tr>');
}
The first loop will display everything in your array (including any entries over 10)
The second loop will display lines to complete the table (if there are less than 10 entries)