How to get a number value from an input field?

后端 未结 3 491
粉色の甜心
粉色の甜心 2020-12-15 10:55

I have some issues with calculating some stuff with JS and getting the right values out of the input fields (number). When I use this code it doesn\'t show anything. So what

3条回答
  •  醉酒成梦
    2020-12-15 11:14

    You had some mistakes in your HTML, but here is a working JSFiddle: Fiddle

    You you are trying to get elements by their ID, but you don't give them an ID you give them a Name. Also, stop using inline JavaScript calls; it is bad practice.

    function Calculate() {
        var TotalProductionTime = document.getElementById("TotalProductionTime").value;
        var TotalProductionTimeInMinutes = TotalProductionTime * 60;
        var Breaks = document.getElementById("Breaks").value;
        var Malfunctions = document.getElementById("Malfunctions").value;
        var TheoreticalProductionTime = TotalProductionTimeInMinutes - Breaks - Malfunctions;
    
        document.getElementById("test").innerHTML = TheoreticalProductionTime;
    }
    Availability
    Total Production Time hours
    Breaks minutes
    Malfunctions minutes
    Theoretical production time:

提交回复
热议问题