Connecting Tech Pros Worldwide Help | Site Map

Select Menu Option <create on the fly>

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2006, 12:35 PM
jojowebdev@gmail.com
Guest
 
Posts: n/a
Default 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();
}


  #2  
Old July 17th, 2006, 06:15 PM
jojowebdev@gmail.com
Guest
 
Posts: n/a
Default Re: Select Menu Option <create on the fly>

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();
}


jojowebdev@gmail.com wrote:
Quote:
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();
}
  #3  
Old July 17th, 2006, 07:25 PM
Matt Kruse
Guest
 
Posts: n/a
Default Re: Select Menu Option <create on the fly>

jojowebdev@gmail.com wrote:
Quote:
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


  #4  
Old July 18th, 2006, 02:25 PM
jojowebdev@gmail.com
Guest
 
Posts: n/a
Default Re: Select Menu Option <create on the fly>

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:
Quote:
jojowebdev@gmail.com wrote:
Quote:
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.