3

I'm new to Javascript and HTML and am trying to do some form validation. When the validation() fails for some input like

<input type="text" name="firstName" />

I'd like to have an error message show next to the field that was in error. How do I find the location of where to put the message? Or do I have some sort of label that's hidden to set when there is an error? Thanks.

1

1 Answer 1

3

You can have a div tag such as <div id="errorMsg"></div>, and in your javascript, when validation fails, use:

document.getElementById('errorMsg').innerHTML = "error msg";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.