I have an HTML number input and follows a selection for unit types.
<input type="number" id="foo" min = "1" max = "10" value = "2" onblur = "if(Number(this.value)<Number(this.min))this.value=this.min; if(Number(this.value)>Number(this.max))this.value=this.max;">
<select id="foo-unit">
<option value="1000">m</option>
<option value="1">mm</option>
<option value="25.4">inches</option>
</select>
The unit types options are meter (m) and millimeter (mm) for example.
There are limits for the number input, min is 1 meter and max is 10 meters. So if the unit is changed to mm, the min is 1000 mm and the max is 10000 mm.
There are two questions:
- If I switch the unit, how can I change the input box's max/min limit accordingly?
- If there is an input value in the box already, say 1 m. I switch to the unit of mm (or inches), how to change the values of the input box to 1000 mm (or 39.37 inches) accordingly?
Thanks,