Are you calling getWeight() either as a window.onload event handler or just above the closing </body> tag?
If not, that is probably the cause of your problem.
Where are you actually calling getWeight() ?
Also, it's generally not a good idea to have variable names the same as id values.
Also, also, you can hide the 2 elements by default in the css so that they do not appear on page load.