Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!