We can't guess what is wrong just from the snippet of code above. It looks ok, if archaic. (It's not good practice to use inline onclick - use some form of event callback registration instead.)
Can you make a jsFiddle that demonstrates the problem? Include no more that what is needed to show the problem.