On a contact form, I have several input fields. One of those fields, is an email address field:
<input type='text' name='input_email' onChange={this.validateEmail}/>
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
You can use onblur() or onfocusout() . It will call function once you click out of that text field.
Definition and Usage. The onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field).
The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.
You can use onblur()
or onfocusout()
. It will call function once you click out of that text field.
Example:
function myFunction() { var x = document.getElementById("sometext"); x.value = x.value.toUpperCase(); }
<input type="text" id="sometext" onfocusout="myFunction()">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With