I have the code to do it. But it is two functions I hacked together.
Does anyone know if I can "clean" it up some?
THank you.
function onCarrierSelect() {
var frm = document.carrRequestForm.carrierList.selectedIndex ;
var selectCar =
document.carrRequestForm.carrierList.options[frm].text;
var varEl = "<%=varElementName%>";
if (window.opener && !window.opener.close)
var oOption = window.opener.document.createElement('option'); //
assigns object name to create Option tag
insertOptionBefore(varEl, selectCar)
window.close();
}
function insertOptionBefore(varElementName, selectCar)
{
var elSel = window.opener.document.getElementById(varElementNa me);
if (elSel.selectedIndex >= 0) {
var elOptNew = window.opener.document.createElement('option');
elOptNew.text = selectCar;
elOptNew.value = selectCar;
var elOptOld = elSel.options[0];
try {
elSel.add(elOptNew, elOptOld); // standards compliant; doesn't
work in IE
}
catch(ex) {
elSel.add(elOptNew, elSel.selectedIndex); // IE only
elSel.selectedIndex = elSel.selectedIndex -1
}
}
}
Matt Kruse wrote:
jo********@gmail.com wrote:
It is breaking/erroring at:
var oOption = window.opener.document.createElement("OPTION");
If you're trying to do this from IE, you can't.
Creating a new option and adding it to a select list must be done from code
within the same page.
So, in your main document write a function which accepts the new Option()
parameters and creates it there.
Then in your popup, call that function in window.opener to do the work.
--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com