Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass input text as parameter to javascript onblur event?

This is the code for an input text field. What I want is to call the "checkDateFormat" function with the text input as a parameter when the user leaves the field.

Here is the code I've written:

Fecha de prueba: <input type="text" name="date_t" id="date_t" value="22/08/2014" onblur="checkDateFormat(this.date_t.value)"><br>

However I'm sure the function isn't even called.

What am I doing wrong?

like image 473
aarelovich Avatar asked Aug 14 '14 11:08

aarelovich


People also ask

How do you use Onblur in JavaScript?

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). Tip: The onblur attribute is the opposite of the onfocus attribute.

How do you value on blur?

To get the value in TextInput when onBlur is called with React Native, we can get the value from the onEndEditing callback. to set onEndEditing to (e) => console. log(e. nativeEvent.

What is the difference between Onblur and onChange?

onChange is when something within a field changes eg, you write something in a text input. onBlur is when you take focus away from a field eg, you were writing in a text input and you have clicked off it.

What is Onblur and Onfocus in JavaScript?

Definition and Usage Tip: The onblur event is the opposite of the onfocus event. Tip: The onblur event is similar to the onfocusout event. The main difference is that the onblur event does not bubble. Therefore, if you want to find out whether an element or its child loses focus, you could use the onfocusout event.


2 Answers

Try to use,

 onblur="checkDateFormat(this.value)" 

Instead of

 onblur="checkDateFormat(this.date_t.value)"
like image 119
Shijin TR Avatar answered Oct 19 '22 00:10

Shijin TR


Try checkDateFormat(this.value) instead.

like image 25
icke Avatar answered Oct 18 '22 23:10

icke