I am trying to get date from form with input type="date", when I click submit.
Code is written in React. I use Chrome.
<form onSubmit={() => {
let inp = document.querySelector('.tooltipSetDate').value;
console.log(inp)
}}>
<input className="tooltipSetDate" type="date"/>
<input type="submit" value="+" />
</form>
let inp = document.querySelector('.tooltipSetDate').value;
sometimes I get result in format year-day-month, as I need. But 90% variable inp becomes NaN or Null, or empty string or nothing.
Reloading this page or rerendering a component don't help.
I even tried to use npm jQuery, tried to test this code in FireFox, Edge.
Also instead of submit I tried to use input onChange. About 1 of 10 times it gives me a correct result.
In simple HTML file this form blinks for a second with right date, then again nothing.
I can not find an error. Please help!
question from:
https://stackoverflow.com/questions/66064782/input-type-date-doesnt-work-every-time-i-choose-a-date 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…