sbridge Posted October 25, 2019 Share Posted October 25, 2019 Greetings. I used this tutorial [https://www.w3schools.com/howto/howto_js_form_steps.asp] as the basis for a form that I am creating. Everything seems to be great, except for the fact that once I started to use form elements besides a text box (text area, multi-select) the validation doesn't work. I looked at the code but can't seem to figure it out. Can someone help with adjusting the JavaScript validation to include other form elements? Also, is there an easy way to show all the inputted data on the last screen, as part of the confirmation? Thanks in advance! form-test-2.html Link to comment Share on other sites More sharing options...
Funce Posted November 5, 2019 Share Posted November 5, 2019 Your validateForm function only checks input elements as it currently stands. As a textarea element is not an input element, you'll need to add some additional code to the validateForm function. You might be able to get some solid use out of element.querySelectorAll() in this case. Something close to x = document.getElementsByClassName("tab"); y = x[currentTab].querySelectorAll("input"); If you modify what's inside the brackets of querySelectorAll, you may be able to use it get your input, textarea, and select elements. Works just like a CSS selector. Speaking of CSS, you'll also need to add an 'invalid' style for the textarea and select elements. Otherwise, it won't turn red like the others. You could copy the invalid style from the input. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 6, 2019 Share Posted November 6, 2019 The use of form .elements collection will select ALL form elements whatever type. https://www.w3schools.com/jsref/coll_form_elements.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now