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

205
Vistas
How to reload the captcha without refreshing the page

This is my script code for captcha generation :

    var allValue = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y', 'Z','1','2','3','4','5','6','7','8','9','0',];
    var cVal1 = allValue[Math.floor(Math.random()*allValue.length)];
    var cVal2 = allValue[Math.floor(Math.random()*allValue.length)];
    var cVal3 = allValue[Math.floor(Math.random()*allValue.length)];
    var cVal4 = allValue[Math.floor(Math.random()*allValue.length)];
    var cVal5 = allValue[Math.floor(Math.random()*allValue.length)];
    var cVal6 = allValue[Math.floor(Math.random()*allValue.length)];

    var cValue = cVal1+cVal2+cVal3+cVal4+cVal5+cVal6;
    captchaValue.innerHTML = cValue;
    thisValue = "";
    captcha_code.addEventListener('change',function(){
        thisValue = captcha_code.value;
    })

    submitBtn.addEventListener('click',function(){
        if(cValue == thisValue){
            alert('Valid');
        }else if(captcha_code.value == ""){
            alert('Invalid Captcha');
        }
    })

This is my html code for captcha inside the form :

<label for="exampleInputEmail1" class="form-label">Captcha</label>
<div class="captcha">
 <div id="captchaValue"></div>
 <input type="text" name="captcha_code" class="form-control" id="captcha_code" placeholder="" />   
</div>
<a href="/">New Captcha</a>

How to get a new captcha every time I click on the 'New Captcha' button.

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

0

You can disable the reload of the page by setting the href attribute to href="javascript:; Then putting the code that generates the new captcha into a function and calling it every time you click the link. You can create this by using event listener.

 var allValue = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y', 'Z','1','2','3','4','5','6','7','8','9','0',];


function newCaptcha() {
  var cVal1 = allValue[Math.floor(Math.random() * allValue.length)];
  var cVal2 = allValue[Math.floor(Math.random() * allValue.length)];
  var cVal3 = allValue[Math.floor(Math.random() * allValue.length)];
  var cVal4 = allValue[Math.floor(Math.random() * allValue.length)];
  var cVal5 = allValue[Math.floor(Math.random() * allValue.length)];
  var cVal6 = allValue[Math.floor(Math.random() * allValue.length)];
  var cValue = cVal1 + cVal2 + cVal3 + cVal4 + cVal5 + cVal6;
  captchaValue.innerHTML = cValue;
}
newCaptcha();

document.querySelector("#new_captcha").addEventListener("click", newCaptcha);

thisValue = "";
captcha_code.addEventListener("change", function () {
  thisValue = captcha_code.value;
});
<label for="exampleInputEmail1" class="form-label">Captcha</label>
<div class="captcha">
  <div id="captchaValue"></div>
  <input type="text" name="captcha_code" class="form-control" id="captcha_code" placeholder="" />
</div>
<a id="new_captcha" href="javascript:;" >New Captcha</a>

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