2

So I have an input text in my html form, that is marked required. My basic question is - are there any options to change the info text of the message. So instead of the default Please fill out this field I want to set my own messages. Eg: User name exists (for Registration forms) or Email Exist, Too weak Password, etc.

I want to be able to do it in jQuery as well.

Here is my HTML:

<input type="email" placeholder="Email" required="required">

What are my options?

Updated

So this is my solution for jQuery but it didn't work as expected

$('#register').first(function() {
        $(this).attr("oninvalid", "setCustomValidity('This Email has been already register')")
    });

What I do wrong? I want to take the form with id register get the first input and add the oninvalvid parameter

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
GeorgeG
  • 31
  • 4
  • First this isn't the place to make suggestions for HTML5. If you want to contribute to HTML5, you'd need to talk to the W3C. Secondly, I do not know what you're asking,. You can display any message you want anywhere. When you refer to a "default "Please fill out this field" can you provide a screenshot? That sounds like you have some code showing that message, it's unlikely to be a browser default. – dmeglio Sep 05 '15 at 14:19
  • 1
    Similar question: http://stackoverflow.com/questions/10361460/how-can-i-change-or-remove-html5-form-validation-default-error-messages As i remember none of the solutions worked for me... So, it seems that only option (for now) is custom validation... – sinisake Sep 05 '15 at 14:20
  • @dman2306 it is the browser default. I haven't change anything. – GeorgeG Sep 05 '15 at 14:23
  • @nevermind Please add an solution. The answer http://stackoverflow.com/a/10363248/5300687 worked for me! Add and the JQueery if you know how, else I'll do it – GeorgeG Sep 05 '15 at 14:24
  • 1
    Yes, now i tested it too! http://jsfiddle.net/9j6brbmd/ (works in chrome and firefox, at least). No need for(my) answer, since Mahoor13 found it, credits to him. ;) – sinisake Sep 05 '15 at 14:27
  • @nevermind I have a second part that need to explained – GeorgeG Sep 05 '15 at 14:32
  • @GeorgeG, maybe something like this: http://jsfiddle.net/9j6brbmd/1/ with[0] at the end, we actually get DOM element, not JQuery object, and this function applies to it... However, this seems like jQuery-vanillaJS solution, again.... :) It is (maybe) ok if you want to keep your markup clean... but not sure that it is actually more elegant... – sinisake Sep 05 '15 at 14:50
  • @nevermind Actually I want the Jquerry to return from a PHP season. If the user sumit an email that is already registered in one MYSQL database then I return the script. That's what I want the script function – GeorgeG Sep 05 '15 at 14:55

0 Answers0