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

77
Vistas
Javascript function going into endless loop

I have a Javascript function that checks if the datatype of the use input is same as that expected by the control e.g. if a character has been entered in an integer field expected in textbox control. The validation message is displayed correctly but the alert does not go away and the function seems to be going into an endless loop. Any help would be appreciated..

Function is as given below :

public ValidateControl(event: Event, dataType: string) {
    let isValid = true;

    let objControl = event.target as HTMLInputElement;
    let elementId = objControl.id;
    let ctrlValue = objControl.value;

    if (ctrlValue.trim() != '') {
      isValid = Common.ValidateDataType(ctrlValue, dataType);
      if (!isValid) {
        document.getElementById(elementId).focus();
        alert("Check your entry in '" + dataType + "' data type column");
        
      }
    }
  }

<div *ngIf="head.ControlType == 'TextBox'">
<input (blur)="ValidateControl($event, head.DataType)" />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You focus then loose the focus with the alert here which triggers the blur

document.getElementById(elementId).focus();
alert("Check your entry in '" + dataType + "' data type column");

Perhaps reverse those statements order

alert("Check your entry in '" + dataType + "' data type column");
document.getElementById(elementId).focus();
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