Rob Williscroft wrote:
Thomas 'PointedEars' Lahn wrote:
setTimeout("myF oo()",1000);ret urn;
Seriously think about that for a minute! You set probably
thousands of timeouts here (since it runs in a tight loop)
to go off 1000 milliseconds (1 second) later.
You appear to have missed the return statment.
Ah yes. I missed that too. One of the manifestations of DrClue's poor
coding is poor code formatting. The results are hard to read and
comprehend (with the inevitable consequences for code maintenance and
increased chance of erroneous or foolish coding). He wrote:-
| function myFoo()
| {
| for(;;) {
| if(parent.MyFra me)if(parent.My Frame.document)
| if(parent.MyFra me.document.get ElementById("My Input"))
| break;
|
| setTimeout("myF oo()",1000);ret urn;
| }// End forever
| alert(parent.My Frame.document. MyForm.MyInput. value);
| }
(and failed to use spaces to indent the code so that the formatting
would be preserved for all readers)
It is commonly recommended that if statements that only have a single
statement following them still use a block statement, with the single
statement within that block. This avoids confusion as to the logic of
the if statement and avoids mistakes when adding lines of code. If I was
formatting that function I would have formatted it as:-
function myFoo(){
for(;;){
if(parent.MyFra me){
if(parent.MyFra me.document){
if(parent.MyFra me.document.get ElementById("My Input")){
break;
}
}
}
setTimeout("myF oo()",1000);
return;
}
alert(parent.My Frame.document. MyForm.MyInput. value);
}
- as that better exposes the logic of the if statements and makes the
return more obvious. And in doing that it becomes self-evident that the
code was written by a fool. The - for - statement may loop forever,
unless broken, but it cannot loop more than once because it cannot
escape the return stamen it contains, unless it is broken. There is
simply no need to have a - for - statement here at all:-
function myFoo(){
if(
(parent.MyFrame )&&
(parent.MyFrame .document)&&
(parent.MyFrame .document.getEl ementById("MyIn put"))
){
alert(parent.My Frame.document. MyForm.MyInput. value);
}else{
setTimeout("myF oo()",1000);
}
}
- is a simpler and much more rational approach to the same outcome.
Richard.