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.carrRe questForm.carri erList.selected Index;
var selectCar =
document.carrRe questForm.carri erList.options[frm].text;
var varEl = "<%=varElementN ame%>";
if (window.opener && !window.opener. close)
var oOption = window.opener.d ocument.createE lement('option' ); //
assigns object name to create Option tag
insertOptionBef ore(varEl, selectCar)
window.close();
}
function insertOptionBef ore(varElementN ame, selectCar)
{
var elSel = window.opener.d ocument.getElem entById(varElem entName);
if (elSel.selected Index >= 0) {
var elOptNew = window.opener.d ocument.createE lement('option' );
elOptNew.text = selectCar;
elOptNew.value = selectCar;
var elOptOld = elSel.options[0];
try {
elSel.add(elOpt New, elOptOld); // standards compliant; doesn't
work in IE
}
catch(ex) {
elSel.add(elOpt New, elSel.selectedI ndex); // IE only
elSel.selectedI ndex = elSel.selectedI ndex -1
}
}
}
Matt Kruse wrote:
jo********@gmai l.com wrote:
It is breaking/erroring at:
var oOption = window.opener.d ocument.createE lement("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