I'm using a for loop to cycle through some elements with a starting value (seats on a plane).

Here it is:
seatNum - Number of seats to be cycled through
startSeat - seat to begin cycling

I'm calling the function from a form "onsubmit".

The problem comes in the for loop when i try and go get elements with an id naming convention of "s1" "s2" "s3" etc... "s45" "s46" etc... based on the loop counter added to the starting seat. Counting from 0(starting seat) up to seatNum(how many seats).

any idea why by id isn't resolving properly? All others work fine except the last one inside the for loop.

Yes I'm new to programming so i probably don't have the best practices, please be forgiving stylistically.

Rather than adding i to the startSeat value to get the seat id, use startSeat's value right in the loop initialization. I believe what was happening is that you were getting an off-by-one error since your startSeat value was already set and then you were adding i to it which bumped you ahead by one.

the problem is that startSeat can be numbers ranging from 1-104, and seatNum will most always be a single digit, smaller number. so the condition (i<seatNum) above will always fail and skip the loop all together. good thought though.
–
user48202Dec 9 '09 at 5:52

When you say cycle through the seats, I assume you want to continue counting from 1 after you reach the maximum seat? Assuming that numberOfSeats is defined somewhere (I couldn't see it, but you must have it somewhere) you can do this: