0

Hey can anyone tell me why required not working

https://code.sololearn.com/Wy0r6z5zmBQ9/?ref=app

25th Feb 2023, 11:22 AM
Girish Sahu
Girish Sahu - avatar
3 Answers
+ 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/
25th Feb 2023, 12:58 PM
PanicS
PanicS - avatar
+ 2
YOU HAVE TO CHANGE THE TYPE OF YOUR BUTTON TO 'SUBMIT' NOT 'BUTTON' <button type="submit">submit</button>
25th Feb 2023, 11:58 AM
Houda Rouaissi
+ 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.
25th Feb 2023, 12:00 PM
Stefanoo
Stefanoo - avatar