The following works fine in Chrome and Firefox, however in Edge it will alert NaN
no matter the input
I don't know why Edge doesn't support valueAsNumber
on type="number"
, but it does support it on range, week, month, and date:
document.addEventListener('click', function(e) {
if(e.target.nodeName === 'BUTTON') {
alert(e.target.previousElementSibling.valueAsNumber);
}
});
<p><input type="range" value="15"> <button>Alert number</button></p>
<p><input type="week" value="2015-W50"> <button>Alert number</button></p>
<p><input type="month" value="2015-12"> <button>Alert number</button></p>
<p><input type="date" value="2015-12-12"> <button>Alert number</button></p>
Microsoft Edge is having broken behavior on valueAsNumber
. This is reported as bug #669685. In addition, setting valueAsNumber
yields an InvalidStateException.
This is fixed in Microsoft Edge 17682, currently available in an Windows Insider build.