0

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!!

1 Answer 1

2

One thing that immediately stands out is this bit of code:

invalid="<b>First and Last Name missing</b><br/>Please enter your First and Last name."

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:

invalid="&lt;b&gt;First and Last Name missing&lt;/b&gt;&lt;br/&gt;Please enter your First and Last name."

Needless to say, invalid is not a legal HTML attribute and this appears to be being used purely as a javascript hook.

Also, instead of populating the value attribute, you should use placeholder instead:

placeholder="First and Last Name"

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:

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you so much! This was incredibly helpful. YOU ROCK.

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.