Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Why is "onclick" and my function showing as undefined?

I made a form in HTML and am trying to calculate the entered data using JS. When I hit submit on the form VSC shows that my onclick function and the function it is calling are undefined. This was working earlier but now isn't.

<input name="calculate" type="submit" value="Calculate BMR" onclick="formdata()">

<script>
                    function formdata(){
                        var getSystem = document.getElementById("system");
                        var system = getSystem.option[getSystem.selectedIndex].value;
                        var getGender = document.getElementById("gender");
                        var gender = getGender.option[getGender.selectedIndex].value;
                        var age = document.getElementById("age").value;
                        var weight = document.getElementById("weight").value;
                        var height = document.getElementById("height").value;
                        var bmr;
                        if (system=="imperial") {
                            if (gender=="male") {
                                bmr = 66 + ( 6.2 * weight) + ( 12.7 * height) - ( 6.76 * age);
                            }
                            if (gender=="female") {
                                bmr = 655 + ( 4.35 * weight) + ( 4.7 * height) - ( 4.7 * age);
                            }
                            
                        }
                        if (system=="metric") {
                            if (gender=="male") {
                                bmr = 66.5 + (13.75 * weight) + (5.003 * height) - (6.755 * age);
                            }
                            if (gender == female) {
                                bmr = 655.1 + (9.563 * weight) + (1.850 * height) - (4.676 * age);
                            }
                        }
                        
                        document.writeln("<h1> BMR Calculated!<h1><br>");
                        document.writeln("<hr>");
                        document.writeln("Gender: " + gender +"<br>");
                        document.writeln("Age: " + age +"years<br>");
                        document.writeln("Height: " + height +"cms<br>");
                        document.writeln("Weight: " + weight +"kg<br>");
        
                        document.writeln("BMR: " + bmr.toFixed(2) +"kCal<br>");
                    }
                    
                </script>

All the other variables are sourced from the rest of the form. But the submit button just won't work in the first place

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda