changing the language of error message in required field in html5 contact form

后端 未结 9 880

I am trying to change the language of the error message in the html5 form field.

I have this code:



        
相关标签:
9条回答
  • 2020-11-27 13:47
    <input type="text" id="inputName"  placeholder="Enter name"  required  oninvalid="this.setCustomValidity('Your Message')" oninput="this.setCustomValidity('') />
    

    this can help you even more better, Fast, Convenient & Easiest.

    0 讨论(0)
  • 2020-11-27 13:47

    Do it using JS. Grab the class of the error message, and change it's content for whereever it appears.

    var myClasses = document.getElementsByClassName("wpcf7-not-valid-tip");
    
    for (var i = 0; i < myClasses.length; i++) {
        myClasses[i].innerHTML = "Bitte füllen Sie das Pflichtfeld aus.";
    }
    
    0 讨论(0)
  • 2020-11-27 13:51

    HTML:

    <form id="myform">
        <input id="email" oninvalid="InvalidMsg(this);" name="email" oninput="InvalidMsg(this);"  type="email" required="required" />
        <input type="submit" />
    </form>
    

    JAVASCRIPT :

    function InvalidMsg(textbox) {
        if (textbox.value == '') {
            textbox.setCustomValidity('Lütfen işaretli yerleri doldurunuz');
        }
        else if (textbox.validity.typeMismatch){{
            textbox.setCustomValidity('please enter a valid email address');
        }
        else {
           textbox.setCustomValidity('');
        }
        return true;
    }
    

    Demo :

    http://jsfiddle.net/patelriki13/Sqq8e/4

    0 讨论(0)
提交回复
热议问题