-1

I´m getting a NaN out of this script, is it a data type problem and how do i solve it?

       <script>
            function calc(){
                var profile = document.getElementById("profil");
                var hours = document.getElementById("hour");
               
                document.getElementById("result").innerHTML=profile*hours;
            }
        </script>

Present the result like this

               <button onclick="calc()">Calc</button><br>
               <p id="result"></p>
Phelar
  • 11
  • 2

2 Answers2

1

You have to get the value from the element.

var profile = document.getElementById("profil").value;
ArturoGJ
  • 11
  • 1
0

With .getElementById you get a DOM Element.

Supposing "profil" and "hour" are input elements, you want to obtain their values:

   <script>
        function calc(){
            var profile = document.getElementById("profil").value;
            var hours = document.getElementById("hour").value;
           
            document.getElementById("result").innerHTML=profile*hours;
        }
    </script>
Tamajon
  • 21
  • 2