By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,627 Members | 1,916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,627 IT Pros & Developers. It's quick & easy.

Select Menu Option <create on the fly>

P: n/a
Picking up from Friday..
I am still having trouble creating the Select Menu option. I got parts
of the correct syntax but it is still not creating the selected carrier
as an option in the parent page.

Help apprecitate,. I currently have it commented out just to show the
line to you better:

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");
// window.opener.form.[varEl].options.add(oOption);
oOption.innerText =selectCar;
oOption.value =selectCar;
window.close();
}

Jul 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It is breaking/erroring at:
var oOption = window.opener.document.createElement("OPTION");

This is a pop-up window select menu that when a value is chosen will
populate the parent window select menu.

Does oOption need to reference the form[0] and the varEl?
How does it know what form to create an option for?

I see the 4th line trys to do this:

window.opener.form[0].elements[varEl].options[window.opener.form[0].elements[varEl].options.length]
= oOption;

The error I am getting is:
Error: 'undefined' is null or not an object.

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
oOption.innerText =selectCar;
oOption.value =selectCar;

window.opener.form[0].elements[varEl].options[window.opener.form[0].elements[varEl].options.length]
= oOption;
window.close();
}
jo********@gmail.com wrote:
Picking up from Friday..
I am still having trouble creating the Select Menu option. I got parts
of the correct syntax but it is still not creating the selected carrier
as an option in the parent page.

Help apprecitate,. I currently have it commented out just to show the
line to you better:

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");
// window.opener.form.[varEl].options.add(oOption);
oOption.innerText =selectCar;
oOption.value =selectCar;
window.close();
}
Jul 17 '06 #2

P: n/a
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
Jul 17 '06 #3

P: n/a
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
Jul 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.