I am trying to use this script to validate a form:
http://validator.codeplex.com/
I am trying to create an input field that has a default value: “First and Last Name”
<div class="RightForm"><input type="text" id="firstlastname" name="firstlastname"
value="First and Last Name" style="width: 175px; float:right;" validate="form" invalid=
"<b>First and Last Name missing</b><br/>Please enter your First and Last name."
invalidVal="First and Last Name" /></div>
If the person clicks submit without changing that default value, I want the validation to show the script’s default pop up warning with the message “First and Last Name are required…” – Also, I don’t want the field to left empty. So the warning should show up for both cases.
However, right now the script is just showing “Undefined” as opposed to the error message.
Any thoughts on how I can fix? Thank you so much!!
One thing that immediately stands out is this bit of code:
If you use HTML syntax characters in HTML attributes, they must be escaped as entities or you will have broken HTML that javascript may not be able to understand:
Needless to say,
invalidis not a legal HTML attribute and this appears to be being used purely as a javascript hook.Also, instead of populating the
valueattribute, you should useplaceholderinstead:This will probably take care of the issue you’re having, as the field will not actually have a “value”, but the text will appear in the input if left empty.
Aside: If you get fed up with the library you’re using, the de facto jQuery validation library is this one: