javascript - How to change Uptick Increments in HTML Number Input -
i have number input form:
<input type='number' id='select-number'>pick number
i have following questions:
1: default uptick increment 1 (when click arrow on number input, goes value of 1 per click.) how can change that? want go in values of 0.1 (tenths). how do that?
2: secondly, have 2 variables:
feet=true; meters=false;
one true, , other false. how change "max" attribute (using javascript) based on of these 2 variables true? 2 variables come code this:
<input type='radio' id='feet' name='unit_of_measurement'>feet <input type='radio' id='meters' name='unit_of_measurement'>meters <script> feet=document.getelementbyid('feet').checked; meters=document.getelementbyid('meters').checked; </script>
if variable "feet" true, maximum value of input (id='select-number') needs 3. if meters, needs 8.
how can that(^), , how can change uptick increment? help.
note: vanilla javascript only, please
1) change step of input use step=".1"
inside input
tag.
2) change max on radio change add onchange="change()"
sets max and/or step based on checked
html
<input type='radio' id='feet' name='unit_of_measurement' onchange="change()" checked>feet <input type='radio' id='meters' name='unit_of_measurement' onchange="change()">meters
js
function change() { feet = document.getelementbyid('feet').checked; meters = document.getelementbyid('meters').checked; selectnumber = document.getelementbyid('select-number'); if (feet) { selectnumber.max = 300; selectnumber.step = 1; } else { selectnumber.max = 100; selectnumber.step = .3; } };
Comments
Post a Comment