Rob said:
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.MyFrame)if(parent.MyFrame.document)
| if(parent.MyFrame.document.getElementById("MyInput"))
| break;
|
| setTimeout("myFoo()",1000);return;
| }// End forever
| alert(parent.MyFrame.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.MyFrame){
if(parent.MyFrame.document){
if(parent.MyFrame.document.getElementById("MyInput")){
break;
}
}
}
setTimeout("myFoo()",1000);
return;
}
alert(parent.MyFrame.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.getElementById("MyInput"))
){
alert(parent.MyFrame.document.MyForm.MyInput.value);
}else{
setTimeout("myFoo()",1000);
}
}
- is a simpler and much more rational approach to the same outcome.
Richard.