On a contact form, I have several input fields. One of those fields, is an email address field:
JavaScript
x
2
1
<input type='text' name='input_email' onChange={this.validateEmail}/>
2
Right now, I have the email validation function set to the onChange attribute. Thus, while the user is entering characters into the email field, an error message appears the whole time.
I want to change this, so that this.validateEmail
only gets called once when the user leaves that specific input field. How would I accomplish this?
I can’t find any default object events that would solve this issue.
FYI, using ReactJS
Advertisement
Answer
You can use onblur()
or onfocusout()
. It will call function once you click out of that text field.
Example:
JavaScript
1
4
1
function myFunction() {
2
var x = document.getElementById("sometext");
3
x.value = x.value.toUpperCase();
4
}
JavaScript
1
1
1
<input type="text" id="sometext" onfocusout="myFunction()">