Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
¿Cómo pasar el valor de la entrada html a javascript correctamente?

¿Cómo puedo pasar el valor de la entrada html a javascript? Tengo value_1 = 0, pero cuando lo cambio en el formulario de entrada, quiero código dentro si sucede.

 <body> <input type="number" name="a" id="commands"><br> <canvas id="myChart1"></canvas> <script> const value_1 = 0; const value_1 = document.getElementById("commands").value; if(value_1 != 0) { //code } </script> </body>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

agregue un oyente para el evento 'keyup', de la siguiente manera:

 document.getElementById("commands").addEventListener('keyup', (e) => { let value = document.getElementById("commands").value; if (value !== 0) { // code } });

O así:

 document.getElementById("commands").onkeyup = function(e) { let value = document.getElementById("commands").value; if (value !== 0) { // code } }

o con jQuery:

 $('#commands').on('keyup', (e) => { let value = $('#commands').val(); if (value !== 0) { // code } });
about 4 years ago · Juan Pablo Isaza Report

0

Puede pasar el valor de html a JavaScript correctamente usando el siguiente código:

HTML:

 <form onsubmit="return getValue('commands')"> <input type="number" name="a" id="commands"> <canvas id="myChart1"></canvas> </form>

JavaScript:

 <script> function getValue(id) { let value_1 = 0; value_1 = document.getElementById(id).value; alert(value_1); if(value_1 != 0) { //code } return false; } </script>
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar addEventListener con el tipo de evento de cambio o usar la propiedad onchange.

Ejemplo:

 <script> const value_1 = document.getElementById("commands"); value_1.onchange = function(){ if(value_1.value != 0) { console.log("Not 0");//code } } </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!