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

244
Views
Can't get the JS script to output data on HTML page

My code below is a simple form which takes an integer, and a yes/no radio button pair. If 'yes' is selected (the left option) then the value you entered * 0.13 should be displayed - if 'no' is selected (or neither are selected) then the value 0 should be displayed. It is not working as expected - how can I fix this problem?

<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

The issues I found are as follows:

  1. The script hasn't been evaluated yet so solve is not defined. I've used an ID on that button and added an event listener instead.
  2. You should be accessing Form1.Nalog not Form1.nalog (note the capitalisation of the name attribute matters).

Here's a working demo with those changes applied:

<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!