I can display the value of the following input box with
alert(parent.My Frame.document. MyForm.MyInput. value);
But if the frame, the form or the input box doesn't exist I get of course an
error message.
How can I figure out before I display the value if the frame 'MyFrame', the
form 'MyForm' and also the input box 'MyInput' exists without getting an
error message?
Stefan 28 2102
Stefan Mueller wrote: I can display the value of the following input box with alert(parent.My Frame.document. MyForm.MyInput. value);
But if the frame, the form or the input box doesn't exist I get of course an error message.
Use object/feature detection:
<http://jibbering.com/faq/#FAQ4_26>
That FAQ is mainly about checking certain features a browser implements
but those property or object checks can also be applied to your problem.
There is an example in there.
--
Martin Honnen http://JavaScript.FAQTs.com/
Stefan Mueller wrote: I can display the value of the following input box with alert(parent.My Frame.document. MyForm.MyInput. value);
But if the frame, the form or the input box doesn't exist I get of course an error message. How can I figure out before I display the value if the frame 'MyFrame', the form 'MyForm' and also the input box 'MyInput' exists without getting an error message?
Perhaps something similar to this..
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);
}
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Dr Clue wrote: Perhaps something similar to this..
Certainly not!
function myFoo() { for(;;) { if(parent.MyFra me)if(parent.My Frame.document) if(parent.MyFra me.document.get ElementById("My Input")) break;
I have seldom seen such a ridiculous piece of source code.
1. Tight loops are the way to the Dark Side.[tm]
2. if(parent.MyFra me)if(parent.My Frame.document)
if(parent.MyFra me.document.get ElementById("My Input"))
can and should be expressed as
if (parent.frames['MyFrame']
&& parent.MyFrame. document
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. The faster the CPU is, the more timeouts will go off at
approximately the _same_ time. And then it is not over because each of
these thousands of timeouts will set even more timeouts _each_ which will
set more timeouts which ... as myFoo() always called again. That will be
probably 1 million timeouts at the least! A sure way to cripple the user's
system beyond repair.
You sir, who calls himself Dr Clue, have no clue at all. Or you have a
clue and deliberately want harm others, who knows. The fact is: You are
dangerous. You should be condemned to have no computer access at all
for a very long time. FOAD!
PointedEars
> if (parent.frames['MyFrame'] && parent.MyFrame. document
That works great.
Many thanks
Stefan
Stefan Mueller wrote: if (parent.frames['MyFrame'] && parent.MyFrame. document
That works great.
However, the timeout-in-tight-loop problem remains.
In my UFPDB[1], I am using something similar to the following
to ensure availability of a method in another frame.
function makeBanner()
{
var f;
if (parent
&& (f = parent.frames)
&& (f = f['ufpdb_banner'])
&& typeof f.makeLeftBanne r == "function")
{
if (typeof makeBanner.time out != "undefined" )
{
window.clearTim eout(makeBanner .timeout);
delete makeBanner.time out;
}
f.makeLeftBanne r(...);
}
else
{
makeBanner.time out = window.setTimeo ut("makeBanner( );", 250);
}
}
makeBanner();
Your target of testing availability of a DOM element is not much
different to that.
As you can see, in contrast to the harmful solution provided by
"Dr Clue", I do not not set the timeout in a tight loop and I
set it only if necessary, hence there is only one timeout to
go off and if no longer needed, it is properly cleared.
PointedEars
___________
[1] <http://www.pointedears .de/ufpdb/> (always under construction,
so please don't bother with bug reports until further notice)
Matt Kruse wrote: Thomas 'PointedEars' Lahn wrote: can and should be expressed as if (parent.frames['MyFrame'] && parent.MyFrame. document
No it shouldn't.
Try:
if (parent.frames['MyFrame'] && parent.frames['MyFrame'].document)
Yes, yes, I dare forgetting to change one property accessor which bears
almost no meaning in that context regarding any known user agent, if that.
It's your nitpick day today? Then let me nitpick, too: your code as-is is
neither efficient nor does it qualify as a reliable solution regarding the
OP's request as the tests for the host objects, especially the target
element object, are missing. It should read
var o;
if (typeof window != "undefined"
&& (o = window.parent)
&& (o = o.frames)
&& (o = o['MyFrame'])
&& (o = o.document)
&& (o = o.forms)
&& (o = o['MyForm'])
&& (o = o.elements)
&& (o = o['MyInput'])
&& typeof o.value != "undefined" )
{
// access `o.value' here
}
Get a life :-b
PointedEars
Thomas 'PointedEars' Lahn wrote: Matt Kruse wrote: Thomas 'PointedEars' Lahn wrote: can and should be expressed as if (parent.frames['MyFrame'] && parent.MyFrame. document Try: if (parent.frames['MyFrame'] && parent.frames['MyFrame'].document) Yes, yes, I dare forgetting to change one property accessor which bears almost no meaning in that context regarding any known user agent, if that.
Your original syntax had a potential name collision with a global variable
named "MyFrame", which very well might be a realistic case, and very well
might cause a problem.
My correction was to that potential problem, and not intended to be a
complete solution for the OP.
--
Matt Kruse http://www.JavascriptToolbox.com http://www.AjaxToolbox.com
> if (parent.frames['MyFrame'] && parent.frames['MyFrame'].document)
I'm doing my tests exactly like you told me and it works perfect.
But I not really understand why to do
if (parent.MyFrame && parent.MyFrame. document &&
parent.MyFrame. document.MyForm && parent.MyFrame. document.MyForm .MyInput) {
Why can't I just do
if (parent.MyFrame .document.MyFor m.MyInput) {
?
I know it doesn't work but I really don't understand that because I think
that in both cases if the MyInput text box doesn't exist
(parent.MyFrame .document.MyFor m.MyInput) returns false.
Stefan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Oeln |
last post by:
If I want to check for input of an integer I've got the following (I
get the form input with $input = "$_POST"):
if(!ereg("^+$",$_POST)) {
echo "Input is incomplete or incorrect.";
}
If, instead of only getting one 'input' I wanted to get n instances of
input, I'd generate input fields for each of n instances I want in a
for loop, then get the input with:
|
by: lawrence |
last post by:
Google can't find me a good example of how to use the "if exists"
syntax in MySql. Is it right that to use it this way:
INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
I want to insert into a table but only if the table exists.
How does one, in general, from PHP, test for the existence of a table,
without getting an error message?
|
by: Scott Shaw |
last post by:
Hi all,
I was wondering if you could help out with this problem that I am having.
What I am trying to do is detect keyboard input in a while loop without
halting/pausing the loop until the key is pressed (without hitting return).
I looked at serveral faq's on the net and installed the cspan readkey module
and neither seems to work most likey its me since I am getting frustrated.
but anyway here's a sample code.
while (1) {
if...
|
by: Gareth Tonnessen |
last post by:
I need to have a clean way to determine whether a query exists without trying
to open it and getting an error message. Is there a simple way to determine
whether an object exists in a database?
Remove obvious from e-mail address.
Gareth Tonnessen
LuvTruth@att.netNOJUNK
|
by: tshad |
last post by:
I am getting an error on a object name that doesn't exist (according to asp.net), but if you look at the trace, it does.
Here is the error:
*******************************************************************************************
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler...
| |
by: Ryan Ternier |
last post by:
Customers keep getting this error, but we've never been able to
re-produce it.
Any help on this would be awesome.
Here's the error message we get.
Date and Time Occured: Wednesday, June 01, 2005 11:02:20 AM
|
by: Nathan |
last post by:
I have an aspx page with a data grid, some textboxes, and an update button.
This page also has one html input element with type=file (not inside the data
grid and runat=server).
The update button will verify the information that has been entered and
updates the data base if the data is correct. Update will throw an exception
if the data is not validate based on some given rules. I also have a custom
error handling page to show the...
|
by: kkleung89 |
last post by:
Basically, here's what's happening with the program. I have a table of
Customers and a table of Pets, with the latter containing a field
linking it to its customer of ownership. I have a form with all of the
personal information of the customers, and within it is a list box with
all of the pets in it. In the current design, it takes that
information from a query, but since every customer is different, the
query needs to change each...
|
by: lifeisgreat20009 |
last post by:
What might be the possible cause ?
I have created a website using struts framework, jsp
In my transaction page the money is not getting transferred..
When I hit the submit button in my Transaction.jsp page , no transaction happens ..
Only the url changes from
http://localhost:8080/bankfinalproject/jsp/transaction.jsp
to this
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |