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

272
Visualizações
How can I prevent a console error with the following code? (It says the given id is not a function)

I keep getting an error because my javascript says that the element declaring my ID is not a function. Thank you in advance to anyone that can help. I am sure it is a simple solution. My goal is to hide one form while the "single" radio button is clicked. (Ignore the "arm all" text, I'm not sure how it got there or how to take it off). EDIT: I have changed the function names but it seems i am still having the same issue.

// This links form1/form2 to hide & display - onclick for group or single radio buttons

function single(id, text, btn) {
  var groupForm = document.getElementById('form2');
  var singleForm = document.getElementById('form1');
  groupForm.style.visibility = 'hidden';
  singleForm.style.visibility = 'visible';
}

function group() {
  var groupForm = document.getElementById('form2');
  var singleForm = document.getElementById('form1');
  singleForm.style.visibility = 'hidden';
  groupForm.style.visibility = 'visible';
}
<div>
  <div style="position: relative; width: 100%;">
    <div id="form2" class="form">
      <select name="sendingfrom" class="click-op">
        <option value="group-select">arm</option>
        <option value="group-select">all</option>
      </select>
    </div>

    <div id="form1" class="form">
      <select name="sendingfrom" class="click-op2">
        <option value="group-select">waist</option>
        <option value="group-select">shoulder</option>
        <option value="group-select">elbow</option>
        <option value="group-select">wrist_angle</option>
        <option value="group-select">wrist_rotate</option>
        <option value="group-select">left_finger</option>
      </select>
    </div>
  </div>

  <!--onclick value links to javascript-->
<input class="radio-group" type="radio" id="group" name="group-or-single" value="group" onclick="group()">
  <label class="text-group" style="color: black; padding-left: 0px;" for="group">Group</label>

<!--onclick value links to javascript-->
<input class="radio-single" type="radio" id="single" name="group-or-single" value="single" onclick="single()">
  <label class="text-single" style="color: black; padding-left: 0px;" for="single">Single</label>
</div>

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

0

You can use the try catch finally statement, but first in the HTML is the names of the function wrong written. This porblem you cannot solve with the solution i mentioned, only if you using eventlisteners in the javascript code.

In this snippet I corrected the misspeled function names, and i made the try catch blocks for you as an exmaple.

// This links form1/form2 to hide & display - onclick for group or single radio buttons
function single(id, text, btn) {
  try {
    var groupForm = document.getElementById('form2');
    var singleForm = document.getElementById('form1');

    groupForm.style.visibility = 'hidden';
    singleForm.style.visibility = 'visible';
  }
  catch {
    console.log("does not works");
  }
}

function group() {
  try {
    var groupForm = document.getElementById('form2');
    var singleForm = document.getElementById('form1');

    singleForm.style.visibility = 'hidden';
    groupForm.style.visibility = 'visible';
  }
  catch {
    console.log("does not works");
  }
}
    <div id="form3" class="form">
        <select name="sendingfrom" class="click-op2">
            <option value="group-select">waist</option>
            <option value="group-select">shoulder</option>
            <option value="group-select">elbow</option>
            <option value="group-select">wrist_angle</option>
            <option value="group-select">wrist_rotate</option>
            <option value="group-select">left_finger</option>
        </select>
    </div>

<!--onclick value links to javascript-->
<input class="radio-group2" type="radio" id="group2" name="group-or-single" value="group" onclick="group()">  
<label class="text-group2" style="color: black; padding-left: 0px;" for="group">Group</label>

<!--onclick value links to javascript-->
<input class="radio-single2" type="radio" id="single2" name="group-or-single" value="single" onclick="single()">  
<label class="text-single2" style="color: black; padding-left: 0px;" for="single">Single</label>
javascript
html

Use Try Catch statement. Mozilla

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