what lacks on html5 "required" and javascript validation form? and better use which one | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

what lacks on html5 "required" and javascript validation form? and better use which one

19th Apr 2019, 3:11 AM
Avirur Rahman
Avirur Rahman - avatar
8 Answers
+ 6
That’s a good idea. Yes, I would recommend that instead.
19th Apr 2019, 5:04 AM
Rowsej
Rowsej - avatar
+ 6
You could use JavaScript to detect whether or not the browser supports the required attribute, if it doesn’t, then enable the JS form validation.
19th Apr 2019, 6:53 AM
Rowsej
Rowsej - avatar
+ 6
var supported = "required" in element; if(!supported) { enableFormValidation(); }
19th Apr 2019, 7:33 AM
Rowsej
Rowsej - avatar
+ 5
Downsides of HTML ‘required’: some browsers may not support HTML5 yet. Downsides of JavaScript validation: some users may have JavaScript disabled in their browser settings. I would recommend the HTML ‘required’ attribute, because it’s much easier.
19th Apr 2019, 4:05 AM
Rowsej
Rowsej - avatar
+ 4
if I use both, is it better for example if the browser does not support html5, it will be replaced by JavaScript or vice versa
19th Apr 2019, 4:45 AM
Avirur Rahman
Avirur Rahman - avatar
+ 4
and if the browser supports both whether if the user sends a blank form it will display two warnings
19th Apr 2019, 5:17 AM
Avirur Rahman
Avirur Rahman - avatar
+ 4
how is that?
19th Apr 2019, 7:09 AM
Avirur Rahman
Avirur Rahman - avatar
+ 4
Thanks 👍
19th Apr 2019, 7:48 AM
Avirur Rahman
Avirur Rahman - avatar