I'm planning out some JS and I'm curious as to what you guys think of this approach. I'm validating a form and I have about 10 - 15 required fields.
The approach I'm thinking of taking is to create two global arrays corresponding to the number of required fields(one of 1's and the other 0's). Then I call the function onChange and pass ID for the question into the function.
Since all form fields will not be verified in the same manner I use the supplied ID to determine which portion of a switch statement I need to use. I know that some fields will use the same so I'm going to use a local variable to save the type of validation I'm going to use.
On the appropriate branch of the switch I use getElementsById (using the ID passed into the function) to local the question and test the field. If input value is valid then I make the error message invisible (if it's visible) then make that question's deisgnated value in the array a 1 (location based on supplied ID).
Once the switch completes, I compare the two global variables and if the initially 0 array is now all 1's the submit button becomes enabled.
Is this the most efficient way to do this? Or am I just doing it wrong? I'm trying to make it execute as little code as possible after each field is changed.
I'm still working out my psuedo on paper and would appreciate any input on this matter.
Thanks in advance guys, this site has proved itself to me to be an immensely useful tool.