0
Hey can anyone tell me why required not working
3 Respuestas
+ 3
Buttons have default type of submit, so omitting type will also work.
And when you work with form, you can also set onsubmit event to form tag, it will work same as it work now.
When you use php for example to handle sending of data and redirect to another page, this is preferred way.
Code now works, but even if your data is wrong for example email is not email it miss @ symbol, it will show message "your account created successfuly", because you never do any validation, and you run function on button click not on form submit.
I suggest you to use onsubmit event on form tag to use default validation, like type of input or required field.
Here is more about onsubmit event:
Basic info:
https://www.w3schools.com/jsref/event_onsubmit.asp
More about this topic:
https://www.educba.com/javascript-onsubmit/
+ 2
YOU HAVE TO CHANGE THE TYPE OF YOUR BUTTON TO 'SUBMIT' NOT 'BUTTON'
<button type="submit">submit</button>
+ 1
Change type inside your button.
From
type="button"
to
type="submit"
The submit function inside your js will executed everytime your click regardless of whether the fields are empty or not.