JS working when used normally but not in wordpress

I have a shortcode that prints a simple form, a button is used to submit the form. The problem is that when it’s pressed, the form gets submitted normally, ignoring the js function. I can’t understand why it’s doing this, since trying this locally on XAMPP works (I needed to change something to adapt the js code to WP, but nothing that should change its behavior.

Display a custom name when the user has no name settle in his account

I’m creating a code that shows the First Name for logged in users, using a shortcode, but I noticed that if the user has no name settle, it will display a blank space. How can I set a custom name to show up instead of the blank space? Something like this “Hi >No Name<, please settle your name in your account.”