This preventDefault should be at the top of the function.