On Screen Keyboard - Insert Decimal Into Input Type Number?

I am creating an simple on screen keyboard (osk) and I need to be able to update the the value of an input type number element with a decimal. When I try to add a ‘.’ to a number field, I receive a warning ‘The specified value “.” is not a valid number’. This is of course because it is being recognized as a string. However, when using the hardware keyboard on my laptop the decimal is inserted without issue. What must be done to insert the ‘.’ when using the osk to type in a float value?

My relevant code for updating the value is basically:
event.target.value = (event.target.value + ‘.’)

Can you issue a keypress event for the field instead?

I am setting this in a button click event. On click of the button, I append the value of the input with the text of the button. Also, I am using vanilla js, no jquery.

So… parseFloat() it?

Nope, simulate the pressing of a key on the element itself, so that a change event is not triggered resulting in the ending decimal being rejected.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.