Pass windows references

wxdqz

New Member
I've having a real problem passing windows references in my javascript code. The problem here is with the onchange call. I want to keep the onchange function in the frame document, but I want to change something in the html frame that has the select box. The onchange function is called, but I can't seem to pass the correct window reference. If I keep the onchange event in the same window as the select box and only pass the id, everything works fine.
Here is all the code I'm using (except for the dummy document). What happens with this is that the setting of var d in the do_something module causes an 'undefined' error. Please help...I've become really stumped

First the frame document:
<html>
<head>
<title>Some Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<SCRIPT SRC=http://www.webdeveloper.com/forum/archive/index.php/"/test/test.js"></SCRIPT>


<frameset border=0 rows="*,1" id="framehead">
<frame src="/test/test.htm" id="frame1" name="frame1">
<frame src="/test/dummy.htm" id="frame2" name="frame2">
<noframes>
This document can only be viewed with a frames-capable browser. Please upgrade your browser
</noframes>
</frameset>

</html>

Now for the test.htm document:
<html>
<head>
<title>Some Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<FORM ID="test">
<SCRIPT language=JavaScript>top.display_yesno(top.frame1,"ref1")</SCRIPT>
</FORM>
</body>
</html>

Finally the script file:
function display_yesno (mywin,ref) {
var d = mywin.document;
var i;
var myref = ref + "_sub";

d.write('<SELECT id="' + ref + '" name="' + ref + '" onchange=top.do_something("' + mywin + '",' + ref + ')>');
d.write('<OPTION value=http://www.webdeveloper.com/forum/archive/index.php/0>No</OPTION>');
d.write('<OPTION value=http://www.webdeveloper.com/forum/archive/index.php/1>Yes</OPTION>');
d.write('</SELECT>');
top.do_something (mywin,ref);
}
function do_something (mywin,ref) {
var d = mywin.document;
var idx = d.getElementById(ref).selectedIndex;
alert(idx);
}
 
Back
Top