IDs must be unique within the page - you currently have duplicates.
As your post's title suggests, you could use class-names and, rather than getElementById(), use getElementsByClassName(), which is supported in most modern browsers. This is just general advice, as I am not clear on what your specific question is(?).
Please wrap your code in code tags!