1

How can i set wait time for this function.

function UpdateMedicaitonHistory(data) {
     MedicaitonHistoryGrid();
//set a wait time to finish MedicaitonHistoryGrid() like for 3 seconds
// then execute the below code.
if ($("#MedHistoryGridSec").is(":visible")) {
            alert("yes we have grid");
      }
else{
     alert("No Grid");
    }
}
HaBo
  • 13,999
  • 36
  • 114
  • 206
  • 1
    Shouldn't you rather add a callback to `MedicationHistoryGrid()` that would execute when it has finished, instead of trying to guess when it's ready? – JJJ Apr 25 '12 at 17:32
  • well it has a chain and dependencies which is not allowing me to do that way. That's why to keep it simple i choose this way. – HaBo Apr 25 '12 at 18:30

3 Answers3

9

You can use setTimeout:

setTimeout(function()
{
     if($('#MedHistoryGridSec').is(':visible'))
         alert('yes');
     else
         alert('no');
}, 3000);
Tejs
  • 40,736
  • 10
  • 68
  • 86
0

You could wrap up the code in a callback function and run it after three seconds using window.setTimeout:

var afterThreeSeconds = function() {
  if ($("#MedHistoryGridSec").is(":visible")) {
    alert("yes we have grid");
  }
  else{
    alert("No Grid");
  }
}

window.setTimeout(afterThreeSeconds, 3000);
rjz
  • 16,182
  • 3
  • 36
  • 35
0

Can you add a parameter to the medication history grid function taking a function containing the code you want executed after that function succeeds which you can then call at the end of the medication history grid function?

Rich Andrews
  • 4,168
  • 3
  • 35
  • 48