Desired Result
I'm attempting to create a generic method in Javascript (JQUERY) which checks the page for any and every element whether it is nullable or not.
As a example I'm using a login.
Both the username and password are not nullable. In my head I think it may be possible to have a error label, which is standard hidden, with a for='<inputbox name here>'
. Then I can loop through all labels which have the class that shows that the label belongs to a input.
Example
<label for="i_1_s_1">Name: </label>
<input type="text" name="i_1_s_1">
<label class="notnullerror" for="i_1_s_1">hidden</label>
<label for="i_1_s_2">Password: </label>
<input type="text" name="i_1_s_2">
<label class="notnullerror" for="i_1_s_2">hidden</label>
Problem
I'm unaware what the best practice is for this. Basicly what I want is a
foreach (var element = document.getElementsByClass('notnullerror')
{
document.getElementsByName(element.for.value);
}
However, this is done in javascript and not jquery and ofcourse, this will not work. How can I manage to make this the way I want?
And, if this is not best practice for showing a error message on a not nullable input, please comment on what is.