473,395 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Simple question about cross-window dropdown list loading

Here is a SIMPLE problem that I'm trying to solve.
It works in Netscape 6.2, but IE6 gives ""No such interface
supported."

Below are page1.htm and page2.htm .

In page1.htm, there are two dropdown lists. If you change the
selection of the left one (e.g. choose parentoption2), it
should open up page2.htm in a popup window.

page2.htm has its own dropdown list. When this page finishes loading,
the onload() its <BODY> will call copyback() which copies the
contents of that dropdown list to the rightmost dropdown list on
page1.htm. In the blink of an eye, the page2.htm popup window
then closes itself.

So, the end result should be that the right dropdown list in
page1.htm, instead of having "What?","What?","What?" as options
as it does originally, it should end up having childoption1,
childoption2, and childoption3.

*Should* be. I thought the best way to do this "replace one node
with another" is to use replaceChild (in page2.htm).
(Is there a better way of doing it? There is removeChild but it's
not part of W3C, I don't believe.)

(What I'm trying to get out of all this is to have the first
dropdown list hold, say, a list of people. When a person is selected,
the Javascript opens up a second page which will be something
like a Perl or PHP script that connects to a SQL database,
grabs all the phone numbers for that person, puts them in a
temporary dropdown list on that page, then copies that list
to the rightmost dropdown list of the first page.

I know that this must be a very common requirement, but I haven't
yet found any web site that shows code to do exactly this, and
I certainly don't mind being told how I'm doing it all wrong!
)

It works in Netscape 6.2, but not in IE6! At the replaceChild
step in page2.htm, IE6 gives the fatal error
"No such interface supported.", usually followed by the browser
completely terminating (nice).

I don't think the problem is replaceChild per se, as I got the
same error when trying other DHTML stuff like mergeAttributes(),
etc, in the same environment, i.e. I think *possibly* the problem
is that it's not designed to handle this kind of cross-window
copying??

I saw Microsoft KB support article Q237831 which kind of implies
that you can't create stuff in one context (window or frame) and
try to use it in another window or frame.
This is at (note that it's all one line!) :
support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/s
upport/kb/articles/Q237/8/31.ASP&NoWebContent=1

Unfortunately, I tried the example in the article, which the article
says won't work for IE5, but it DOES work for IE6 - at least, it
worked for me. So it's not helping in solving my problem.

What DOES work is if I comment out the
parentnode.replaceChild(newnode,oldnode);
return;
lines in page2.htm, so that it continues and gets to the code
which copies the select list option by option. Unfortunately,
it is far too slow - in certain situations there are going to be
thousands of options in the dropdown list.

----page1.htm----
<html>
<head>
</head>
<body>
<select onchange='window.open("page2.htm","popup","toolbar =no, width=500,
height=250, left=0, top=0")'
name="selectlistparent1" >
<option value="30">parentoption1</option>
<option value="31">parentoption2</option>
</select>
<select
name="selectlistparent2" >
<option value="4">What?</option><option
value="5">What?</option><option value="6">What?</option>
</select>
</body>
</html>
----page2.htm----
<html>
<head>
<script>
<!--
function copyback() {
newnodes=document.getElementsByName('selectlistchi ld');
newnode=newnodes[0];

oldnodes=opener.document.getElementsByName('select listparent2') ;
oldnode=oldnodes[0];
//echodebug('oldnode.nodeName: '+oldnode.nodeName,1);

parentnode = oldnode.parentNode;
// IE6 can't handle this: "No such interface supported."
parentnode.replaceChild(newnode,oldnode);
return;

// -------
// Instead of using replaceChild above, can copy the options
// one by one:

// Empty the recepient dropdown list in the parent window,
// by making a non-deep clone of it, then replacing itself
// with the clone. Then assign 'oldnode' variable to once
// again point to it.
oldnodeclone = oldnode.cloneNode(false);
oldnode.parentNode.replaceChild(oldnodeclone,oldno de);

oldnodes=opener.document.getElementsByName('select listparent2') ;
oldnode=oldnodes[0];

// Copy the options from the dropdown list in the child window, to
the
// recepient dropdown list in the parent window.
for (i=0;i<newnode.options.length;i++) {
// This does work to copy them individually. But it's way too
slow.
oldnode.options.length++;
oldnode.options[i].text = newnode.options[i].text;
oldnode.options[i].value = newnode.options[i].value;
}

window.close();

}

// -->
</script>
</head>
<body onload="copyback()">
<select name="selectlistchild" >
<option value="1">childoption1</option>
<option value="2">childoption2</option>
<option value="3">childoption3</option>
</select>
</body>
</html>
Jul 20 '05 #1
1 8242
Yep
ba*******************@unspamar.com.au (Joseph Barron) wrote in message news:<3f******@nexus.comcen.com.au>...
In the blink of an eye, the page2.htm popup window
then closes itself.
What about using a hidden (i)frame? Logic remains the same, and you
avoid blinking (moreover window.open may is not safe in an Internet
env). If you're sure of your env you could also use XmlHttpRequest I
think.
It works in Netscape 6.2, but not in IE6! At the replaceChild
step in page2.htm, IE6 gives the fatal error
"No such interface supported.", usually followed by the browser
completely terminating (nice).
Well, I've got IE5.5 and get the same results, as you note here...
I saw Microsoft KB support article Q237831 which kind of implies
that you can't create stuff in one context (window or frame) and
try to use it in another window or frame.
.... this is a normal behavior, the real pain is that IE doesn't
currently support advanced DOM2 features (also note that DOM2 offers
an importNode method and DOM3 adoptNode method for the Document
interface, which would please you if supported).
What DOES work is if I comment out the
parentnode.replaceChild(newnode,oldnode);
return;
lines in page2.htm, so that it continues and gets to the code
which copies the select list option by option.
That's unfortunately the generally accepted solution, regarding your
code I'd just recommend not to use window.open in the onchange handler
(you'll prevent any keyboard navigation for the select, such as arrows
and letters) and use getElementById over getElementsByName.
Unfortunately,
it is far too slow - in certain situations there are going to be
thousands of options in the dropdown list.


Maybe re-think your process then (functional solution), do some
intermediate layer, select boxes with thousands entries aren't
generally appreciated; or just have the server sends a parseable
string and have innerHTML write it (technical solution). This could be
much faster than DOM manipulation, and (probably) more cross-browser.
The result is impressive in IE (7 times faster), correct in Mozilla
(1.5 times faster) and not worth it in Opera 7 (DOM manipulation a bit
faster, innerHTML doesn't seem to communicate directly with the
parser):

<script type="text/javascript">
function f(){
var d=document;
var s=d.createElement("select");
for(var ii=0; ii<1000; ii++){
var opt=d.createElement("option");
opt.value="v"+ii;
opt.text="t"+ii;
s.appendChild(opt);
}
document.getElementById("test").appendChild(s);
}
function g(){
var s="<select>";
for(var ii=0; ii<1000; ii++)
s+="<option value='v"+ii+"'>t"+ii+"<\/option>";
document.getElementById("test").innerHTML=s+"<\/select>";
}
function runTest(){
var d1=new Date();
f();
var d2=new Date();
g();
var d3=new Date();
alert("f:"+(d2-d1)+"\n"+"g:"+(d3-d2));
}
</script>
<div id="test"></div>
<input type="button" onclick="runTest()" value="test!">
A quick script follows as illustration (if you happen to go for this
conception or something similar, I'd however suggest that you adopt a
more structured approach defining clearly the interface and message
objects):
page1.htm
<script type="text/javascript">
function generate(where, what){
switch (where) {
case "csel" :
var parts=what.split(":"), buf=["<select>"];
for(var ii=0; ii<parts.length; ii+=2){
buf.push(
"<option value='"+parts[ii]+"'>"+
parts[ii+1]+
"<\/option>"
);
}
document.getElementById("csel").innerHTML=buf.join ("");
break;
}
}
function test(){
//document.getElementById("csel").innerHTML="Loading ...";
frames.buffer.location.href='page2.htm';
}
</script>

<input type="button" value="load!" onclick="test()">
<div id="csel">
<select>
<option value="4">What?</option>
<option value="5">What?</option>
<option value="6">What?</option>
</select>
</div>
<iframe width="0" height="0"
style="visibility:hidden" name="buffer"></iframe>

page2.htm (server's response):
<html>
<head>
<title></title>
<script type="text/javascript">
window.onload=function(){
var db=document.body;
if(top.generate && db)
top.generate("csel",db.innerHTML);
}
</script>
</head>
<body>
value 1:child 1:value 2:child 2:value 3:child 3
</body>
</html>
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dario de Judicibus | last post by:
I wish to create two simple layouts by using only HTML, CSS and the minimum JavaScript as possible. Layouts should be "elastic" (no fixed widths and heights) and cross-browser enabled. The first...
5
by: Rich | last post by:
I have a simple, single threaded program in C++ that runs as Idle priority. The program creates some data which needs dumping to file if the computer is shutdown or logged out. At the moment...
3
by: Iain Miller | last post by:
Can anybody help me with some Access 2000 code? I don't do a lot of coding in Access & so every time I come back to do something I pretty much have to relearn the syntax from scratch so this is...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
1
by: Arjen | last post by:
Hi, Im trying to make / looking for a very very simple WYSIWYG editor. Ive made a (ad free) site about dogs but it's attracting way more visitors then I could ever have imagined. I have a forum...
1
by: P2P | last post by:
Hi Does anyone know a simple cross-broswers vertical scrolling javascript that can call up its scrolling contents off an external html page/file? Much appreciated -- P2P...
6
by: Daz | last post by:
Hi everyone. I am trying to figure out if it's possible to dynamically change the value of a textNode. I seem to remember experiementing before I implemented them into my page, and I was able...
5
by: kkddrpg | last post by:
the database looks like this the database is called username_tpp (not really just using username as a sub) the table is called home it has field 1 : varchar(50) | latin1_swedish_ci | no...
1
by: NevilleDNZ | last post by:
Hi, Apologies first as I am not a unicode expert.... indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python...
1
by: Ciaran | last post by:
Hi Does anyone have a simple function that captures a keystroke that works cross browser? I just want to redirect a page when a user hits esc... you'd think it would be easy! Cheers, Ciarán
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.