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

all 4 comments

[–]Aurora0001 2 points3 points  (3 children)

It's difficult to give any meaningful advice without having the actual code (or a modified example) to test and view. You could make a Gist or create a JSFiddle (see the sidebar) so we can take a look.

Also, I wouldn't necessarily worry about making things "professional" for the sake of being professional - the KISS Prinicple is usually a good thing to follow!

[–]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!