Javascript this.value onchange not working

I'm trying to get the value of a form input usign JS:

HTML:

<td onchange="validate_hours(this)">{{ form.monday }}</td>

JS:

function validate_hours(elem) {
   console.log(elem.value)
}

But I receive "undefined".

The {{ form.monday }} is a Django form

Django form:

<input type="number" name="form-0-monday" value="4.0" step="any" placeholder="0.0" id="id_form-0-monday">

I found a solution, I used firstChild to get the input and now is returning the value:

JS

function validate_hours(elem) {
  input = elem.firstChild.value
  console.log(input)
}
Back to Top