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

245
Views
No se puede obtener el script JS para generar datos en la página HTML

Mi código a continuación es una forma simple que toma un número entero y un par de botones de opción sí/no. Si se selecciona 'sí' (la opción de la izquierda), entonces se debe mostrar el valor que ingresó * 0.13; si se selecciona 'no' (o no se selecciona ninguno), entonces se debe mostrar el valor 0. No funciona como se esperaba. ¿Cómo puedo solucionar este problema?

 <html lang="ru"> <head> <meta charset="utf-8"> <title>Калькулятор</title> </head> <body> <FORM NAME="Form1"> <p><b>Какая у вас ЗП?</b></p> <INPUT TYPE="number" id="salary" class="value" placeholder="Enter an integer" /> <p><b>Ваш подоходный налог 13%?</b></p> <INPUT TYPE="radio" name="Nalog" id="da" value="Yes">Да <INPUT TYPE="radio" name="Nalog" id="net" value="No">Нет <br>Посчитаем сумму налога? <INPUT TYPE ="button" value="Посчитать" onClick="solve();"> <p id="result"></p> </form> <script> var output = document.getElementById("result"); function solve() { var input = document.getElementById("salary").value; output.innerHTML = ""; if (document.Form1.nalog[0].checked) { output.innerHTML = input * 0.13; } else { output.innerHTML = 0; } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Los problemas que encontré son los siguientes:

  1. La secuencia de comandos aún no se ha evaluado, por lo que la solve no está definida. Usé una identificación en ese botón y agregué un detector de eventos en su lugar.
  2. Debería acceder a Form1.Nalog no a Form1.nalog (tenga en cuenta que las mayúsculas del atributo de nombre son importantes).

Aquí hay una demostración de trabajo con esos cambios aplicados:

 <html lang="ru"> <head> <meta charset="utf-8"> <title>Калькулятор</title> </head> <body> <form NAME="Form1"> <p><b>Какая у вас ЗП?</b></p> <INPUT TYPE="number" id="salary" class="value" placeholder="Enter an integer" /> <p><b>Ваш подоходный налог 13%?</b></p> <INPUT TYPE="radio" name="Nalog" id="da" value="Yes">Да <INPUT TYPE="radio" name="Nalog" id="net" value="No">Нет <br>Посчитаем сумму налога? <INPUT TYPE="button" value="Посчитать" id="submit"> <p id="result"></p> </form> <script> var output = document.getElementById("result"); var btn = document.getElementById("submit"); btn.addEventListener("click", solve); function solve() { var input = document.getElementById("salary").value; output.innerHTML = ""; if (document.Form1.Nalog[0].checked) { output.innerHTML = input * 0.13; } else { output.innerHTML = 0; } } </script> </body> </html>

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!