Perform input type input with button

0

I hope this question does not sound absurd but I have to make an input but without using input I have to capture only numbers and always round to the nearest, pure whole numbers ie: entry = & 149; output => 100 and perform the buttons that normally appear with an input of type number (the arrows above and below) but winged from the field where we enter the number

[entry of the default number is 100 and will go from 100 in 100 to 500, whether they are typed by the user] [top and bottom arrows are used to change the aforementioned amounts and go from 100 500 or 500 to 100 according to the user (do not decrease or increase, simply by giving the clcik lower 100 another click another 100 as the case)]

I know that the last thing can be done with js or jquery, but I hope the idea is understandable.

    
asked by Jorge Gutierrez Yañez 23.06.2018 в 01:55
source

2 answers

0

From what I have understood what you want is to receive a number and round it to 100,200,300,400 or 500 and show it on the screen. This way you can get something similar to what you want, details are missing but I think it can help you:

function redondear() {
var entrada = Math.round(parseInt(document.getElementById("entrada").value));
  if (isNaN(entrada)) {
    entrada = 0;
  } else if (0 <= entrada && entrada <= 49) {
    entrada = 0;
  } else if (50 <= entrada && entrada <= 149) {
    entrada = 100;
  } else if (150 <= entrada && entrada <= 249) {
    entrada = 200;
  } else if (250 <= entrada && entrada <= 349) {
    entrada = 300;
  } else if (350 <= entrada && entrada <= 449) {
    entrada = 400;
  } else {
    entrada = 500;
  }
var p = document.getElementById("p");
  p.innerHTML = entrada;
}
<input type="text" id="entrada" onkeyup="redondear()" value="100" />
<p id="p">100</p>
    
answered by 23.06.2018 в 14:32
0

what you say, in fact the functionality can be set with javaScript, now for the conversion of your numbers, this can help you,

function redondear(num){var numero=Math.round(num/100)*100;alert("Numero 
redondeado:"+numero)}
    
answered by 23.06.2018 в 02:41