Jack King Jack King - 3 months ago 30
HTML Question

increment float number with javascript

i want button (+) to increment 0.3 and (-) discrement by 0.3 with range



function move1(){
var x1l = document.getElementById("imjv1l").value;

document.getElementById('val_img1_l').value=x1l;
}

<input type="range" min="0" max="100" value="50" step="0.1" style="width:100%;" oninput="move1(this.value)" id="imjv1l">
<output id="val_img1_l">50</output><br>
<input type="button" value="+"><input type="button" value="-">




Answer

    function increment(plusMinus) {
        var x1l = parseFloat(document.getElementById("imjv1l").value);
        x1l += plusMinus * 0.3;
        x1l = x1l.toFixed(2)
        document.getElementById("imjv1l").value=x1l;
        document.getElementById("val_img1_l").value=x1l;

    }

    function move1(){
    	var x1l = document.getElementById("imjv1l").value;

        document.getElementById('val_img1_l').value=x1l; 
    }
	
    <input type="range" min="0" max="100" value="50" step="0.1" style="width:100%;" oninput="move1(this.value)" id="imjv1l">
    <output id="val_img1_l">50</output><br>
    <input type="button" value="+" onclick="increment(1)"><input type="button" value="-" onclick="increment(-1)">	

5

Comments