3

Is it possible to control HTML5 alert messages? when adding 'required' to an input field.

because I want it to be specific and I don't want it's language to depend on the browsers.

<input id="answer" required>
user3013190
  • 133
  • 1
  • 10

3 Answers3

2

You can use customValidity

$(function(){
    var elements = document.getElementsByTagName("input");
    for (var i = 0; i < elements.length; i++) {
        elements[i].oninvalid = function(e) {
            e.target.setCustomValidity("This can't be left blank!");
        };
    }
});

I think that will work on at least Chrome and FF, I'm not sure about other browsers

scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
1

Thank you guys for the help,

When I asked at first I didn't think it's even possible, but after your answers I googled and found this amazing tutorial:

http://blog.thomaslebrun.net/2011/11/html-5-how-to-customize-the-error-message-for-a-required-field/#.UsNN1BYrh2M

user3013190
  • 133
  • 1
  • 10
0

Yes:

<input required title="Enter something OR ELSE." />

The title attribute will be used to notify the user of a problem.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592