'Start a javascript calculation from an html input without using a function

Not sure if this question is asked before and maybe it is a simply question, but I couldn't find it espescally for my problem.

I have a html page with javascript. In the html I have an input field for the date of birth. With a click button, I trigger a function in my script where I get the value of the date of birth with the document.getElementById and with that date of birth as an variable and the date of today, I can calculate the age and this age is being exposed in the html as well.

The calcution and exposing of the age is al working fine and correct. But my question is: In my current situation, I have a function, which is been triggered by a button to calculate the age. Is it also possible to do this calculation without a function, so just right away? That you just fill in the date of birth and that then automatically the age is being calculated in the output field?

Like I said, maybe it is a stupid or silly question, but I just started learning scripting and found a lot with google, but not an anwser to this question.



Solution 1:[1]

I found it. Still have to use a function, but not using the onClick, but the onKeyUp in the field.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ervee