473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Select Menu Option <create on the fly>

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
3 2660
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan | last post by:
Hi, I would just like to know if the istream operator takes only one parammeter(object) at a time (like z) ? istream operator>>(istream& in, Shape &z) Cause I keep getting error concerning the...
6
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while...
2
by: Jasonkimberson | last post by:
I am doing a data pull of HTML from a database that will be put into a drop down menu currently after i pull and populate the information, it converts my < into &lt; whats the work around for...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
1
by: frey | last post by:
i tried to create a dropdown menu and use the option as a control to change content inside another text area the code is like this: <select name="xxxx"><option onclick="changeunitprice(29.87)"...
4
by: Kentor | last post by:
I have some info that im grabbing from a mysql database with php and i want to make an xml file but i know that i need to be carefull with the & sign and so on... how can i clean the data coming...
5
by: Screaming Eagles 101 | last post by:
Hi , not much trouble in making a setup project, but I'd like also an icon in All Programs to uninstall the application. I can't find a good explanation on the net so far... -- Filip...
5
by: consonanza | last post by:
I am working on a report filter form. It has 2 combo boxes (cmboSelectSubject and cmboSelectCategory) to select criteria. Selecting an entry in combo 1 restricts the options available in combo 2....
5
by: Hels Bells | last post by:
Hi, I'm looking to do some manipulation on a string containing html code in asp which will involve me either using some regular expressions or just plain old simple replace functionality. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.