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

141
Visualizações
JS Calculator Gives `getElementById is not defined`

what's the problem in this code? I have tried and can't figure it out. I am a total newbie in HTML, JavaScript, and CSS. I am wandering around the internet but I think I am missing something and its a small mistake. can you kindly help? I have to learn this for my upcoming projects

here is the code

function result() {
  let a = getElementById("constant").value;
  let b = getElementById("height").value;
  let c = getElementById("freq").value;
  let sum = Number(a) + Number(b) + Number(c);
  document.getElementById("Calculate").value = sum;
}
<form>
  Di-Electric Constant: <input class="text" Placeholder="Enter Value" id="constant" </input>
  <br> Di-Electric Height: <input class="text" Placeholder="Enter Value" id="height" </input>
  <br> Operational Frequency: <input class="text" Placeholder="Enter Value" id="freq" </input>
  <br>

  <br>
  <input type="text" id="Calculate" </input>
  <input type="button" value="Calculate" onclick="result()">
</form>
<br/>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is document.getElementById(). See: MDN WebDocs: document.getElementById().

The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.

function result()
{

let a = document.getElementById("constant").value;
let b = document.getElementById("height").value;
let c = document.getElementById("freq").value;
let sum = Number(a) + Number(b) + Number(c);

document.getElementById("Calculate").value = sum;

}
<!DOCTYPE html>
<html>
<head>
<h1>Microstrip Calculator</h1>
<p>Enter the following values in numeric form:</p>
</head>
<body>
<form>

Di-Electric Constant: <input class="text"Placeholder="Enter Value" id="constant"</input>
<br>
Di-Electric Height: <input class="text"Placeholder="Enter Value" id="height"</input>
<br>
Operational Frequency: <input class="text"Placeholder="Enter Value" id="freq"</input>
<br>

<br>
<input type="text"id="Calculate"</input>
<input type="button" value="Calculate" onclick="result()"> 
</form>
<br/>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
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