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)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.