[Javascript] Re: [Solved] Mozilla valid javascript not working in IE
Luciano Ruete
luciano at lugmen.org.ar
Mon Sep 6 22:09:19 CDT 2004
Luciano Ruete escribiste :
> The code is simple, a parent opens a popup on demand, and the popup
> child reads a textbox, and add a option with the typed text in the
> parent's select object.
> This code works ok in Mozilla and Firefox, but when i tested in Internet
> Explorer and Opera does not.
>
> parent.html:
>
> myPopup = '';
> function openPopup(url) {
> myPopup = window.open(url,'popupWindow','width=640,height=480');
> if (!myPopup.opener)
> myPopup.opener = window;//also tested with self and this
> }
>
>
> son.html:
>
> var i = opener.document.forms[0].comboXXX.length;
> myNewOption = new Option("nevo item" ,23, true);
> opener.document.forms[0].comboXXX.options[i] = myNewOption;
> window.close();
>
>
> The code is generated whit php, here the php variables are hardcoded to
> simplify the script, also the function calls and the php if's.
>
> I discovery that forms[0] and options[i], must be forms[1] and
> options[i+1] in Opera (i do not have IE to test, sorry linux fan :-).
> But even with those changes, the parents select gets a new option, but
> whit no value, ie a blank select element. And the new option is not
> selected by default. Later test it in IE(a friend house) and same
> result: a new select blank option in the parent.
> I test a hardcoded.html version like i send in this post, no php involved.
>
> Attached father and son html's, with array starting at 1, working in
> opera with the blank option add.
>
> Regards!
>
I googled and try so far, finally i found this[1]:
Explorer 5.0 problems:
<quote>
When it comes to dynamically generating options and selects, Explorer
5.0 on Windows has quite a few problems:
1. Generating options in another frame or window doesn't work. Put
the script in the page that contains the select.
</quote>
So i moved the logic to the father, and it works, inline solution, works
in mozilla, opera and finally in Internet Exploder.
[1]http://www.quirksmode.org/js/options.html
--
Luciano
father.html
-----BEGIN BLOCK-----
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function openPopup(url) {
myPopup = window.open(url,'popupWindow','width=640,height=480');
if (!myPopup.opener)
myPopup.opener = window;
}
function copyForm() {
var i = document.testForm.tipo.length;
var myNewOption = new
Option(myPopup.document.popupForm.myTextField.value, i, true);
document.testForm.tipo.options[i] = myNewOption;
document.testForm.tipo.selectedIndex = i;
myPopup.window.close();
return false;
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Open Popup" onClick="openPopup('son.html')">
</FORM>
<FORM NAME="testForm" ACTION="nextPage.html">
<select name="tipo">
<option value="">--select--</option>
<option value="0">xxx</option>
<option value="1">yyy</option>
</select>
<input name="ok" value="Ok" type="submit" />
</FORM>
</BODY>
</HTML>
-----END BLOCK-----
son.html
-----BEGIN BLOCK-----
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
//--></SCRIPT>
</HEAD>
<BODY>
<FORM NAME="popupForm">
<INPUT TYPE="TEXT" NAME="myTextField">
<INPUT TYPE="BUTTON" VALUE="Submit" onClick="opener.copyForm()">
</FORM>
</BODY>
</HTML>
-----END BLOCK-----
More information about the Javascript
mailing list