Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

326
Vistas
How can I make an HTML Form be hidden when entering the webpage?

I am trying to make a form that opens upon clicking a button, and close upon clicking a button.

To achieve this, I made the following code:

function showForm() {
  document.getElementById('testForm').style.display = 'block';
}


function closeForm() {
  document.getElementById('testForm').style.display = 'none';
}
<button type="button" class="btn btn-primary shadow" onclick="showForm()">Add Expense</button>

<form id="testForm">
  <input type='text' placeholder="Test">
  <button onclick="closeForm()">Close Form</button>
</form>

However, the form is automatically displayed upon entering the website, instead of being automatically hidden and displaying the form upon clicking the Add Expense button. How would I approach this?

Test Form

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can add a custom class or style attribute on your to be hidden on page load like below.

<form id = "testForm" style="display:none;">
        <input type = 'text' placeholder = "Test">
        <button onclick = "closeForm()">Close Form</button>
    </form>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Add default styling to your form.

Either do it inline:

<form id="testForm" style="display: none;">
   <input type='text' placeholder="Test">
   <button onclick="closeForm()">Close Form</button>
</form>

Or in a css file/tag:

#testForm {
  display: none;
}

This will cause your form to be hidden by default. Then when your "showForm()" function is triggered, the style gets overridden and the form is displayed.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda