I am trying to change the language of the error message in the html5 form field.
I have this code:
<input type="text" name="company_name" oninvalid="setCustomValidity('Lütfen işaretli yerleri doldurunuz')" required />
but on submit, even the field is not blank, I still get the error message.
I tried with <input type="text" name="company_name" setCustomValidity('Lütfen işaretli yerleri doldurunuz') required />
but then the english message is displayed. Anyone know how can I display the error message on other language?
Regards,Zoran
setCustomValidity‘s purpose is not just to set the validation message, it itself marks the field as invalid. It allows you to write custom validation checks which aren’t natively supported.You have two possible ways to set a custom message, an easy one that does not involve Javascript and one that does.
The easiest way is to simply use the
titleattribute on the input element – its content is displayed together with the standard browser message.If you want only your custom message to be displayed, a bit of Javascript is required. I have provided both examples for you in this fiddle.