1

I set the required attribute to the dropdown list. Now I submit the form without selecting any option of the drop-down it'll give me error msg like "Please select an item in the list."

I want to change this msg ? how to do that ?? HTML Code

<select required  id="doc_type">
user3887375
  • 51
  • 1
  • 1
  • 4

1 Answers1

13

You can use HTML5 event oninvalid

Try this :

<select required  id="doc_type" oninvalid="this.setCustomValidity('Please select an item in the list')" oninput="setCustomValidity('')">
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
  • 1
    Thank you for this, I've never used it before, do you know a way to add a custom CSS class to the message for custm styling? I've tried using `:required` in my CSS file with various selectors, but no joy – Sam Mar 20 '18 at 09:13
  • Thank you it really helps me in critical time :) – Rakesh Prajapati Jul 26 '19 at 07:06