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

351
Visualizações
Html textbox visible with button click

How can i make a html textbox invisible and then it becomes visible when a user clicks on a button? That button already has a js funtion to get values from an API but can it also make a textbox visible? Btw i'm using getElementh by id. The textbox is <input type="textbox" id="city"> Thanks

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

0

Assuming you have set display of your textbox to block, you can simply do if using onclick:

<button onclick="showHideTextBox()">Click Me to Show/Hide</button>
<input type="textbox" id="city">
<script>
    function showHideTextBox(){
      var x = document.getElementById("city");
      if (x.style.display === "none") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }
    }
</script>

Instead of block you can add whatever display attribute value you want to add and inside showHideTextBox function you can add other logic which is needed for your api calls.

I found great answer about how to show hide elements in javascript: How to show or hide an element:

about 4 years ago · Juan Pablo Isaza Relatório

0

Yes, That button can also make the textbox visible. Add textbox's visible code to the button's event listener's function along with your existing fetch API function.

const button = document.getElementById("button");
button.addEventListener("click", function(){
  // write textbox's show/hide function
   // call your existing function
})

To show/hide textbox you can toggle a class.

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