mikeb
mikeb

Reputation: 727

When removing alert, the variable becomes undefined

I have three separate tab panels with each being a table in my database. What i'm trying to do is that on a click of a button is save the content of all the three tabs in the database at the same time. I managed to do so by activating the tabs, then passing it certain value. However when i remove both alert functions from my code, i'm getting that B.RECORD is undefined. Any help on this?

      tabPanel.setActiveTab(1);
      tabPanel.setActiveTab(2);
      tabPanel.setActiveTab(0);

var B= window.frames["frm_B"];
var C= window.frames["frm_C"];

alert(B);
alert(C);
try {
    B.RECORD.getField("AID").setRealValue(aid);
    C.RECORD.getField("AID").setRealValue(aid);
    B.RECORD.update();
    C.RECORD.update();
    parent.refreshGrid();
    parent.win.close();

Upvotes: 0

Views: 59

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167172

This looks like the alert() gives you some time to load the iframes. You need to either use:

  1. setTimeout giving an arbitrary load time for the frames.
  2. Use .load() event of the frames.

I would prefer you use the .load() event, because it is dependable. So for that, put the following code and beyond inside the load event of the iframe:

try {
    B.RECORD.getField("AID").setRealValue(aid);
    C.RECORD.getField("AID").setRealValue(aid);
    B.RECORD.update();
    C.RECORD.update();
    parent.refreshGrid();
    parent.win.close();

The load event can be done using: Javascript callback when IFRAME is finished loading?

Upvotes: 2

Related Questions