Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
¿Cómo llamar a la función cuando cambia el valor de entrada?

He intentado encontrar una forma de llamar a una función cuando cambia el valor de la entrada, pero hasta ahora no he encontrado nada. Todas las cosas que probé parecían funcionar, pero no lo hicieron. HTML:

 var funds = 500; document.getElementById("submit").onclick = function() { } function AP() { if (document.getElementById("p").checked) { document.getElementById("AP").innerHTML = "%"; } else { document.getElementById("AP").innerHTML = ""; } } //right here I'd like the function to call.
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Rng Crypto</title> </head> <body> <header> <h1>Crypto ran from randomness!</h1> </header> <div> <input type="radio" name="AP" id="a" onchange="AP()" checked>Absolute<input type="radio" name="AP" id="p" onchange="AP()">Percent<br> <input type="number" id="input" HERE TO ADD THINGY> <p id="AP" style="display:inline;"></p><br> <button id="submit">Submit</button> </div> <script src="RngCrypto.js"></script> </body> </html>

Las cosas que he probado son:

 <input type="number" id="input" onchange="input()"> <input type="number" id="input" oninput="input()"> <input type="number" id="input" onkeyup="input()"> document.getElementById("input").onchange=input(); document.getElementById("input").oninput=input();
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

 const inputEle = document.querySelector("#input"); inputEle.addEventListener('input', function(e) { console.log(e.target.value); })
 <input type="text" id="input">

¿Ha intentado agregar el evento 'cambiar' en el elemento de entrada?
Editar: agregar eventListener 'input', es una forma más de lograr este resultado.

(consulte el siguiente código)

 var funds = 500; document.getElementById("submit").onclick = function() { } function AP() { if (document.getElementById("p").checked) { document.getElementById("AP").innerHTML = "%"; } else { document.getElementById("AP").innerHTML = ""; } } //right here I'd like the function to call. document.queryselector("#input").addEventlistener('change', function(e) { console.log(e.target.value;) })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Cuando te entendí bien, esto es básicamente lo que estás buscando:

 <input class="js-radio-button" type="radio" name="ab" value="absolute"> Absolute<br> <input class="js-radio-button" type="radio" name="ab" value="percent"> Percent<br> <button class="js-check-selection">CHECK</button> <div> <span>Result is:</span> <span id="result"></span> </div>

en tu javascript tienes:

 function checkSelectedRadio() { // get your radios having the name 'ab' const radios = document.querySelectorAll('input[type=radio][name=ab]'); // reset result container document.getElementById('result').innerHTML = ''; // loop through the radios for (let i = 0; i < radios.length; i += 1) { // check for each radio if it was selected if (radios[i].checked) { // set the value of the selected radio to your result container document.getElementById('result').innerHTML = `Value: ${radios[i].value}`; // if you need more logic: if (radios[i].value === 'absolute') { // do something here if 'absolute' was checked } else if (radios[i].value === 'percent') { // do something here if 'percent' was checked } } } } // get your button to check radio status like this or fire the function above by your onchange handler const checkButton = document.querySelector('.js-check-selection'); checkButton.addEventListener('click', checkSelectedRadio);

EDITAR después de leer tu comentario:

Para detectar el cambio de su campo de entrada, funciona así:

 <input type="number" id="input" value="1">

En tu JS:

 const field = document.querySelector('#input'); function inputCheck() { console.log('input changed'); // or do something else } field.addEventListener('change', inputCheck);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda