/    Sign up×
Community /Pin to ProfileBookmark

Loop while null or undefined.

Hi,
I have another web application that opens in a window and runs a query in it after some simple timeout functions. that works ok but I d like to know at once when it is ready, not an estimated (about 10seconds settimeout()) depending on the clientcomputers cpu.
The question is HOW would I in the best way execute these functions without settimeout, instead use a loop that goes on until all the variables is defined in that application?
The problem is that the variable okToSend in the opened application “is null or not an object” (errormessage) 😑 when I try to check it as below.
Any ideas?
Thanks!//Martin

function imsFunct(){
mapWindow.focus();
var i = 0;
do
{
i+=1;
}
while(((mapWindow.MapFrame.okToSend==”undefined”)||(mapWindow.MapFrame.okToSend==”null”)||(!mapWindow.MapFrame.okToSend)));
setActive();
do
{
i+=1;
}
while(((mapWindow.MapFrame.okToSend==undefined)||(mapWindow.MapFrame.okToSend==null)||(!mapWindow.MapFrame.okToSend)));
findHit();
}

to post a comment
JavaScript

9 Comments(s) ↴

Copy linkTweet thisAlerts:
@KorOct 04.2005 β€”Β 
The problem is that the variable okToSend
[/quote]


I quite don't get what you want to do, but there is an object, not a variable down there. Anyway, I guess that you should use the [b]typeof[/b] operator to checked whether the type of the object/variable is undefined or not
Copy linkTweet thisAlerts:
@gt37authorOct 04.2005 β€”Β the variable (okToSend) is a variable declared inside MapFrame that I use to check when the app is ready for a new request. its true or false.

Anyhow When I try to check the value of it, its not defined at all, since I just open the application in a new window.

So I get the "mapWindow.MapFrame.okToSend" is null or not an object" as soon as I try to check it.

The IFs for undefined or null should have taken care of this but somehow it does not work. Tried with or without quotes.


How could I use typeof condition? sounds interesting
Copy linkTweet thisAlerts:
@herodote92Oct 04.2005 β€”Β I guess the child window would have to set a parent-window variable to 'true' when it's ready. This variable would have been set previously to 'false' by the parent window itself, so it would never be undefined.

Well, that's just a general idea, I might be wrong...
Copy linkTweet thisAlerts:
@gt37authorOct 04.2005 β€”Β It worked with a variable in the opener set to true by the window.!

BUT...I get the "[I] a script on this page make internetexplorer run slow" do you want to abort the script? If you dont the computer might hang up.[/I]

How could I do a loop without this alert popping up?
Copy linkTweet thisAlerts:
@herodote92Oct 04.2005 β€”Β Every time I got such a message it came out that there was a bug of mine somewhere.
Copy linkTweet thisAlerts:
@herodote92Oct 04.2005 β€”Β Oh, I hope you used a timeout for your loop ? Because if you just test the flag continually without breathing, the message you got would be quite justified. You should test it every, say, 100 or 500 milliseconds, or so.
Copy linkTweet thisAlerts:
@gt37authorOct 05.2005 β€”Β No sorry to say I did not use a timeout or interval

How could I achive that?

I did like below:

function imsFunct1(){

var i = 0;

mapWindow.focus();

do {i=i+1 }

while(!loaded);

setActive();

setTimeout("findHit();",500);

}
Copy linkTweet thisAlerts:
@herodote92Oct 05.2005 β€”Β I made a small example here. Clicking the button won't change directly the message: it will only set the flag to TRUE. The background routine checks this flag every 2 secunds, when it finds it's TRUE, it changes the message. That's why there can be a delay between clicking and seeing the message changing. The background routine shouldn't be much time-consuming.

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Getting flag from somewhere else&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;

&lt;script type="text/javascript"&gt;
var my_flag = false;
var t = "";
var ctr = 1;

function TestIt() {
t = setInterval("STestIt();",2000);
}
function STestIt() {
if (my_flag) {
clearInterval(t);
var msg = "Hurrah! Flag value is TRUE !&lt;br&gt;I checked for it "+ctr+" time(s) !"
document.getElementById("my_text").innerHTML = msg;
}
else ctr++;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload = "TestIt();"&gt;
&lt;input name="" type="button" value="Click" onclick="my_flag=true;"&gt;
&lt;br&gt;&lt;br&gt;
&lt;div id="my_text"&gt;
Alas, Flag value is still FALSE...
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@gt37authorOct 05.2005 β€”Β Thanks alot KOR and HERODOTE92, this last bit was very handy to learn!

It now works great and runs the code quick as it is possible. ?

The results became two checks of this "loop" type of check

var t1="";

var varv = 1;

function checkOkToSend(){

t1=setInterval("chkOKTS();",500);

}

function chkOKTS(){

mapWindow.focus();

if(''+mapWindow.MapFrame.okToSend+''=="true"){

clearInterval(t1);

setActive();

findHit();

}

else varv++;

}

var t = "";

var ctr = 1;

function imsFunct() {

t = setInterval("STestIt();",500);

}

function STestIt() {

if (loaded) {

clearInterval(t);

mapWindow.focus();

//alert("loaded");

checkOkToSend();

}

else ctr++;

}
Γ—

Success!

Help @gt37 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 6.16,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...