Vanza Setiaβ’ 27,795
@vanzasetia
Posted
Hello, Enis67! π
Here are some suggestions to improve your JavaScript:
- Avoid using
var
. Useconst
orlet
instead. - Avoid using JavaScript to add styling (unless you have no other option). JavaScript allows you to change the CSS code using the
style
property. But, to make debugging easier and improve code maintainability, itβs best to avoid it. Use CSS classes instead. - Use
js-
classes to grab elements within JavaScript. - Use regular expression to validate the email address.
Next, some suggestions for the form validation:
- Each input element must have an accessible name. In this case, you can use
aria-label
attribute to provide an accessible name for each input. - Each of the
<p>
elements for the error messages should be programmatically connected with the associated<input>
element. You can do that by usingaria-describedby
attribute. - Also, each of the error messages should be a live region. You should use
aria-live
attribute. This way, screen readers will pronounce the error as soon as the region gets populated with the message through JavaScript. - Make sure the
<p>
for the error messages should be empty initially. - Learn more β How To Create Accessible Form with Simple Design? β Vanza Setia
I hope this helps. Happy coding! π
0