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

91
Vistas
hide a message after 3 seconds and my code displaying multiple times

I am running an ajax call and when i try to submit, my input field gets an another div underneath it and shows error, but if i click the button too many times, it keeps on adding new messages one under the another

and also i want to hide the message after 3 seconds

so basically two problems in my code

$.ajax({
            url : $('##frm').attr('data-action'),
            type: 'post',
            data: $('##frm').serialize(),
            success: function(data) {
                if (data.indexOf("emailissue") > -1) {
                    $("##emailaddress").parent().after("<div class='validation' style='color:red;font-size:0.90em;'>Please Provide valid email address</div>");
                    $('##validation').delay(3000).fadeOut();
                }else{
                    $("##ID").show().delay(5000).fadeOut();
                    $("##ID").css('display','none');
                }
             }
        });

html is like this

<div class="form-group">
                      <label for="emailaddress">We are missing you email, please enter below</label>
                      <input type="text" name="emailaddress" id="emailaddress" placeholder="Enter your email" class="form-control">
                    </div> 
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try setting a static response element in the DOM:

<div class="form-group">
  <label for="emailaddress">We are missing your email, please enter it below</label>
  <input type="text" name="emailaddress" id="emailaddress" placeholder="Enter your email" class="form-control">
  <div id="response" class="validation"></div>
</div> 

Then in the response from your ajax call, update the contents and visibility of the #response element:

if (data.indexOf("emailissue") > -1) 
{
  $("#response").show().text('Please Provide a valid email address');
  setTimeout(function(){
      $('#response').fadeOut();
  }, 3000);
}

By toggling between hiding/showing the #response element, we no longer need to worry about additional response elements being added, or deleting older ones.

Here is a DEMO I made. Click the "Test" button to the right to see it.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Why do you have double '##' when you try to select the element?

Also after 3 second you need to remove the new created div from the DOM,

it's not enough to just call the fadeOut() (my guess it's just set opacity 0)

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