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.
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.
Share Improve this question asked Oct 26, 2011 at 0:47 J WJ W 8781 gold badge12 silver badges25 bronze badges 1- 1 Why not use jQuery validation plugin? – Emmanuel N Commented Oct 26, 2011 at 0:52
1 Answer
Reset to default 3You 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";