Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:03:26+00:00 2026-05-17T19:03:26+00:00

Here is the code: $(#inputtxt).change(function() { var doneflag = 0; var testname = ;

  • 0

Here is the code:

$("#inputtxt").change(function() {

var doneflag = 0;
var testname = " "; 
var rawinput = $('#inputtxt').val();
var scnt = 0;
var indata = {};
$('#inputtxt2').val("");
$('#lnghost').show();
$('#lnghost2').hide();

// go load some arrays from data in a database  
getDBaseData(fnarray,lnarray,flarray);

//  Option 1:
//  $(function() {
//          setInterval("doneflag=1;", 5000);
//  });

//  Option 2:
//  while (doneflag == 0) {
//      t1 = setTimeout("doneflag = 1;",5000);
//      };

//  Option 3:
//      alert('Found 0 |'+fnarray[0] + '|' + lnarray[0]+'Found 1 |'+fnarray[1] + '|' + lnarray[1]+ ' doneflag is '+doneflag);

$.each(fnarray, function(i,val) { ... yada yada yada 

Here’s what’s happening:
It’s supposed to work such that the getDbaseData function runs, gets data from the database, load the arrays, then come back and run on. Instead, what’s happening is that the getDbaseData function takes off, and this program keeps going so that it hits the .each function BEFORE the arrays are populated.

Between these two statements I have 3 options commented out that I have tried.
– The setInterval doesn’t seem to do anything that I can tell.
– The while loop runs indefinitely
– the alert statement seems to make everything run fine, even though it pulls up empty fields from the array. But it seems to stop things long enough for the dbase call to catch up.

Of course I don’t want the alert statement. Am I doing something obviously wrong? Does anyone know how to fix this?
Help is much appreciated.

========================== Update ======================
Okay, I’ve read the answers below, but some of you wanted to see the getDbaseData function, so here it is:

<script type="text/javascript">
function getDBaseData(fnlist,lnlist,fllist) {
/* First call the php routine to get the database values, then process that info based on the following statements */
$.getJSON('getnames.php', {indata: $("#inputtxt").val() }, function (data) { 

    var newHTML = ' ';
    var doneflag = 'false';

    if (data[0].first == ' ') {
        fnlist[0] = 'none';
        lnlist[0] = 'none';
        fllist[0] = 'none';
        return false;
    };
            $.each(data,function(l, val) {
                  newHTML += '<li>' + data[l].first + ' ' + data[l].last + '</li>';
                  fnlist[l] = data[l].first;
                  lnlist[l] = data[l].last;
                  fllist[l] = 'hide';

            });
            $('#NameList').html(newHTML);  /* part of test code */
       });  /* end of getJSON call */
    };
 </script>

I’ve tested every part of this function, and it returns exactly what it is supposed to, so I don’t believe there is any logic problem here. I had not considered putting everything into the callback function, but I will try that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:03:27+00:00Added an answer on May 17, 2026 at 7:03 pm

    Since the function is making asynchronous calls, it’s not going to wait. However, you do have the callback handlers in those ajax calls, and can put your each function there so it happens after the data is populated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to match this block here /code\ int foo(string $bar, int $bleh); Simple
I'm facing a little problem with Primefaces and Facelets . Here's the problem: I
Example of input: I 67 85 49 R 4 D 4 G 65 97
I have a text file with a rather large amount of data of about
A very simple JSF applicaton: InputText element is assigned with Validator. f:ajax is used
This is going to seem extremely trivial, but it just doesn't make any sense
I have search functionality in my app, in which when user clicks in textbox,
I have an auto complete field which is working perfectly, and fetch the data
I am running into a peculiar problem when I am trying to invoke h:inputText

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.