Comincio a pensare che il codice JS non c'entra e che il problema risieda nel codice html. Che ne dite ?