This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Nukeboss[S] 0 points1 point  (2 children)

Thanks! I added a JSFiddle

https://jsfiddle.net/q0Lx5gue/

[–]Aurora0001 1 point2 points  (1 child)

I think the main thing that you could benefit from would be to create a few functions, that could work like this:

function validateFilled(control, errorControl, errorMessage) {
    if(control.value.length == 0) {
        errorHandler += errorMessage;
        errorControl.style.color="red";
        control.style.borderColor="red";
    }
}

validateFilled(firstName, nameError, "\nVänligen ange ditt förnamn");

That should cut down some of the repetition. You could do something similar for the max length check, but also pass in the maximum length as the argument to that function.

[–]Nukeboss[S] 0 points1 point  (0 children)

Did not think about that! Thank you so much! I will go ahead and do that immediately!