First of all, using var inside an if() block really isn't a good idea. It's valid but scope in JavaScript is function-wide so it exists outside the if() block.
...which can lead to all manner of confusion. And most JS lint tools will flag it.
Another thing to remember - events propagate, so unless you stop propagation, the "enter" will cause your event handler to be run but still add a newline since that's the default thing to do when the key is pushed.
You might want to paste a little bit more of your code so we can see how the event handler for key presses is registered.