N
N
Nikita Konin2015-10-09 16:15:12
JavaScript
Nikita Konin, 2015-10-09 16:15:12

Entering text into input does not change value. How to fix?

There is an input field: I'm trying to get the entered value using: (All this, of course, is inside a function that is a handler for changing the input)
<input id="datetime_from" type="text">

let input = document.getElementById("datetime_from");
let result = normalizer(input.value);

But value is always empty, even if something is entered and I then try to get the value. Those. The error isn't that the handler doesn't fire.
14b24f5250e14c2baa0a644e2e5762fb.png
UPD.
Just in case, I give the normalizer code
let normalizer = function (date) {
        let res = /(\d\d).(\d\d).(\d\d\d\d)/.exec(date);
        if (!res)
            return '';
        let normalized = `${res[3]}-${res[2]}-${res[1]} 00:00:00+03:00`;
        return normalized;
};

UPD.2
All this is inside the django admin with the suit theme.
UPD.3
Even if I just open the page, enter text in the field, and then write in the browser console
console.log(document.getElementById("datetime_from").value)

still empty.
(Which actually illustrates the screenshot).
Both firebug and built-in dev tools give:
<input id="datetime_from" type="text">

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivanq, 2015-10-09
@Ivanq

Maybe replace let with var?
Then maybe see what happens without the normalizer()

L
lega, 2015-10-09
@lega

You may have 2 or more #datetime-from there (i.e. with one id)

A
Alexey P, 2015-10-09
@ruddy22

Can you add an event handler?
Not much, maybe it will help?
window.addEventListner('onchange ', handler, somethingElse);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question