2

Is it possible to change the language of the error message required? I know that I can add a message in my language required title="Message", but I want to change the languge of the default: please fill out this field. In other words: I do not want to supply a custom text. I want to force a language for the default messages.

I tried setting the lang attribute and also sent a Content-Language header but it always uses the browser's default language instead.

How can I do this? Thank you in advance.

Rob
  • 14,746
  • 28
  • 47
  • 65
user3272713
  • 167
  • 2
  • 5
  • 15
  • 1
    ah it's quite incomplete your question can you elaborate? Show us what you are trying – fefe Feb 13 '14 at 21:34

1 Answers1

1

Since you're using HTML5 for validation, I'm assuming this only needs to support the latest browsers. So, you can use the JavaScript method setCustomValidity().

The string you supply to that method will change the error message for its member DOM element, which shows when the contents are invalid.

HTML:

<form>
    <input id="eml" type="email" required />
    <input type="submit" />
</form>

JavaScript:

document.getElementById('eml').setCustomValidity('Dude. That e-mail is whack!');

jsFiddle

Alex W
  • 37,233
  • 13
  • 109
  • 109