473,403 Members | 2,293 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,403 software developers and data experts.

IE not grabbing SELECT value

I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result in
the correct response when 'Show Me' is clicked. But IE only shows the
result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:
function updateList(what)
{
// This dynamically populates the CurrentPositionPicks select box in
the resume page
// depending on what one was selected in the LevelOne select box.
for (var i=0;i<document.Resume.CurrentPositionPicks.length; i++) //
empty the list
{
document.Resume.CurrentPositionPicks.options.lengt h=0;
}

// LevelOnePicks is the top level select box in the resume form
// CurrentPositionPicks is the dynamically generated select list
var CurrentPositionPicks=document.Resume.CurrentPositi onPicks;
for (var i=0;i<document.Resume.LevelOnePicks.length;i++)
{
if (document.Resume.LevelOnePicks.options[i].selected)
{
var ThisList=eval(TopLevel[i].Name); // get the array name to use
for (var j=0; j < ThisList.length; j++)
{
CurrentPositionPicks.options[j]=new Option;
CurrentPositionPicks.options[j].text=ThisList[j];
}
}
}
}
Jul 23 '05 #1
6 5967
Amer Neely wrote:
I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result in the correct response when 'Show Me' is clicked. But IE only shows the result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:
function updateList(what)
{
// This dynamically populates the CurrentPositionPicks select box in the resume page
// depending on what one was selected in the LevelOne select box.
for (var i=0;i<document.Resume.CurrentPositionPicks.length; i++) //
empty the list
{
document.Resume.CurrentPositionPicks.options.lengt h=0;
}

// LevelOnePicks is the top level select box in the resume form
// CurrentPositionPicks is the dynamically generated select list
var CurrentPositionPicks=document.Resume.CurrentPositi onPicks;
for (var i=0;i<document.Resume.LevelOnePicks.length;i++)
{
if (document.Resume.LevelOnePicks.options[i].selected)
{
var ThisList=eval(TopLevel[i].Name); // get the array name to use
for (var j=0; j < ThisList.length; j++)
{
CurrentPositionPicks.options[j]=new Option;
CurrentPositionPicks.options[j].text=ThisList[j];
}
}
}
}


The two browsers handle multiple selects differently. To get selected
option values/texts cross-browser, you need to loop the options and
examine them. In addition, your updateList() function isn't setting
option values, just displayed text. Some browsers will substitute the
latter for the former but, don't rely on it...set both.

function Output()
{
var o,
picked = [],
msel = document.Resume.CurrentPositionPicks;
for (var i = 0, l = msel.length; i < l; ++i)
{
if ((o = msel.options[i]).selected)
picked.push(o.text);
}
alert(
'You chose\n' +
document.Resume.LevelOnePicks.value +
':' +
picked.join(' | ')
);
}

Matt Kruse will now plug his script. #:=D

Jul 23 '05 #2
Amer Neely wrote:
I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result in
the correct response when 'Show Me' is clicked. But IE only shows the
result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:


I would use a simpler technique:

<script type="text/javascript">
window["night spots"]=["Café Royale","Maxim's","Rose and Crown"];
cars=["ford","dodge","buick"];
countries=["USA","UK","East Timor"];

function populateMenuWithArray(menu,array){
var alen=array.length;
menu.options.length=0;
for(var i=0;i<alen;i++){
menu.options[i]=new Option(array[i],array[i]);
}
}

</script>

<form action="some.html" method="get" name="f">
<select name="a" onchange=
"if(this.selectedIndex)
populateMenuWithArray(this.form.b,
window[this[this.selectedIndex].text]);">
<option selected>Select One</option>
<option>cars</option>
<option>countries</option>
<option>night spots</option>
</select>
<select name="b"></select>
Mick (tested)

snip
Jul 23 '05 #3
Mick White wrote:
Amer Neely wrote:
I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result in
the correct response when 'Show Me' is clicked. But IE only shows the
result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:

I would use a simpler technique:

<script type="text/javascript">
window["night spots"]=["Café Royale","Maxim's","Rose and Crown"];
cars=["ford","dodge","buick"];
countries=["USA","UK","East Timor"];

function populateMenuWithArray(menu,array){
var alen=array.length;
menu.options.length=0;
for(var i=0;i<alen;i++){
menu.options[i]=new Option(array[i],array[i]);
}
}

</script>

<form action="some.html" method="get" name="f">
<select name="a" onchange=
"if(this.selectedIndex)
populateMenuWithArray(this.form.b,
window[this[this.selectedIndex].text]);">
<option selected>Select One</option>
<option>cars</option>
<option>countries</option>
<option>night spots</option>
</select>
<select name="b"></select>
Mick (tested)

snip


Thanks for the quick response - I do like your simpler function. But IE
still only shows the second SELECT box choice.

I'm going to try the suggestion by RobB about looping through the list
boxes.
Jul 23 '05 #4
RobB wrote:
Amer Neely wrote:
I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result


in
the correct response when 'Show Me' is clicked. But IE only shows the


result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:
function updateList(what)
{
// This dynamically populates the CurrentPositionPicks select box in


the resume page
// depending on what one was selected in the LevelOne select box.
for (var i=0;i<document.Resume.CurrentPositionPicks.length; i++) //
empty the list
{
document.Resume.CurrentPositionPicks.options.lengt h=0;
}

// LevelOnePicks is the top level select box in the resume form
// CurrentPositionPicks is the dynamically generated select list
var CurrentPositionPicks=document.Resume.CurrentPositi onPicks;
for (var i=0;i<document.Resume.LevelOnePicks.length;i++)
{
if (document.Resume.LevelOnePicks.options[i].selected)
{
var ThisList=eval(TopLevel[i].Name); // get the array name to use
for (var j=0; j < ThisList.length; j++)
{
CurrentPositionPicks.options[j]=new Option;
CurrentPositionPicks.options[j].text=ThisList[j];
}
}
}
}

The two browsers handle multiple selects differently. To get selected
option values/texts cross-browser, you need to loop the options and
examine them. In addition, your updateList() function isn't setting
option values, just displayed text. Some browsers will substitute the
latter for the former but, don't rely on it...set both.

function Output()
{
var o,
picked = [],
msel = document.Resume.CurrentPositionPicks;
for (var i = 0, l = msel.length; i < l; ++i)
{
if ((o = msel.options[i]).selected)
picked.push(o.text);
}
alert(
'You chose\n' +
document.Resume.LevelOnePicks.value +
':' +
picked.join(' | ')
);
}

Matt Kruse will now plug his script. #:=D


Ah, that figures. Thanks for the direction and the sample code.

Jul 23 '05 #5
RobB wrote:
Amer Neely wrote:
I have a page showing dynamic generation of a SELECT box using
JavaScript. See http://www.softouch.on.ca/dynamic.html.

Using Mozilla et al, choosing an option from both lists will result


in
the correct response when 'Show Me' is clicked. But IE only shows the


result from the first SELECT box. Any ideas why / how to fix this?

The function I'm using:
function updateList(what)
{
// This dynamically populates the CurrentPositionPicks select box in


the resume page
// depending on what one was selected in the LevelOne select box.
for (var i=0;i<document.Resume.CurrentPositionPicks.length; i++) //
empty the list
{
document.Resume.CurrentPositionPicks.options.lengt h=0;
}

// LevelOnePicks is the top level select box in the resume form
// CurrentPositionPicks is the dynamically generated select list
var CurrentPositionPicks=document.Resume.CurrentPositi onPicks;
for (var i=0;i<document.Resume.LevelOnePicks.length;i++)
{
if (document.Resume.LevelOnePicks.options[i].selected)
{
var ThisList=eval(TopLevel[i].Name); // get the array name to use
for (var j=0; j < ThisList.length; j++)
{
CurrentPositionPicks.options[j]=new Option;
CurrentPositionPicks.options[j].text=ThisList[j];
}
}
}
}

The two browsers handle multiple selects differently. To get selected
option values/texts cross-browser, you need to loop the options and
examine them. In addition, your updateList() function isn't setting
option values, just displayed text. Some browsers will substitute the
latter for the former but, don't rely on it...set both.

function Output()
{
var o,
picked = [],
msel = document.Resume.CurrentPositionPicks;
for (var i = 0, l = msel.length; i < l; ++i)
{
if ((o = msel.options[i]).selected)
picked.push(o.text);
}
alert(
'You chose\n' +
document.Resume.LevelOnePicks.value +
':' +
picked.join(' | ')
);
}

Matt Kruse will now plug his script. #:=D


This solution worked perfectly (but I changed the order of display).
Thanks again.
Jul 23 '05 #6
Amer Neely wrote:
Mick White wrote:


function populateMenuWithArray(menu,array){
var alen=array.length;
menu.options.length=0;
for(var i=0;i<alen;i++){
menu.options[i]=new Option(array[i],array[i]);
}
}

</script> snip

Thanks for the quick response - I do like your simpler function. But IE
still only shows the second SELECT box choice.

I'm going to try the suggestion by RobB about looping through the list
boxes.


Works for me, IE 5.2(Mac), FF 1.0(mac), Moz 1.7.3(Mac), Safari 1.03
Mick
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... I'm wondering if anyone knows how or has the resource for graabing a users email address without them knowing? Before I hear all the 'Its not ethical'...
0
by: T. | last post by:
How do you assign a value of type OLE BSTR to a C# string as shown by this code snippet. I am getting an 'EXCEPTION_ACCESS_VIOLATION...' runtime error. SQLDMO.SQLServer; SQLDMO.Database db;...
4
by: darrel | last post by:
I have a contact form that a person submits to the server. In ASP, you'd make a page, post the form to another page, which would grab the values and do somethign with them. in ASP.NET, it...
2
by: Darrel | last post by:
I have a control that transforms an XML file using XSLT. I also want to grab a particular variable out of the XML file. I thought an easy way to do this would be no have the XSLT just find the...
1
by: darrel | last post by:
Is there any way to detect the specific version of an MS Office document when accepting it from an upload? I'm creating a mini-document upload tool for people to manage some MS-office centric...
3
by: Bengt Richter | last post by:
Has anyone found a way besides not deriving from dict? Shouldn't there be a way? TIA (need this for what I hope is an improvement on the Larosa/Foord OrderedDict ;-) I guess I can just document...
0
by: .Net Sports | last post by:
I've been looking everywhere, but i can't locate any functions, or articles on the net or my resources, on how to open a file using vb.net, and then grabbing certain parts of the file, and putting...
0
by: hoderbob | last post by:
I have written a printer tracking and user validation application to control color printing abuse at my office. I have one small problem. The spooled print job does not report copies. For...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.