I can't seem to figure out this inconsistency in the code below. Shouldn't (x.value) be the same as (y)? Why are they returning different values?
Thanks in advance for the help.
html:
<form>
<input name="startDate" type="date" value="">
</form>
<button onclick="getDate()">click</button>
javascript:
var x = $("input[name=startDate]")[0];
var y = $("input[name=startDate]")[0].value;
function getDate() {
console.log(x.value); // returns what i've chosen in the datepicker (eg. 2018-05-14)
console.log(y); // returns an empty string
}
ygives you the value of the input field, whenxandyare created.x.valuewill give you the current value of the input at the timegetDate()is caled.