Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  60] [ 2]  / answers: 1 / hits: 122499  / 12 Years ago, sun, may 27, 2012, 12:00:00

From reading this post I have found that there are some pseudo classes for 'valid' and 'invalid' input values introduced to HTML5.



Is there a way I can mark an input field as invalid/valid from javascript? Or alternatively, can I override the validation method used?


More From » html

 Answers
27

You could use the customValidity function for this purpose.



If you add a customValidity message to the field, it becomes invalid. When you set the message as an empty string, it becomes valid again (unless it is invalid because of other reasons).



field.setCustomValidity(Invalid field.); will make the field invalid.



field.setCustomValidity(); will make the field valid unless it fails an HTML5 constraint.


[#85318] Friday, May 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
prestonh

Total Points: 384
Total Questions: 105
Total Answers: 105

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;