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

Selecting all items in a multiple select: inconsistency with Internet Explorer

P: n/a
Hi

I was wondering if anyone else had had this problem before (can't find
anything on the web about it).

I have three select elements (list boxes - from here on I'll refer to
them as 'the list boxes'). Users can add and remove items from the
list boxes.

When the users are adding and removing items, the list boxes are single
selection only. However, when the form is submitted, I want ALL items
to be submitted. So I have written the following script,which ensures
that all elements in each box are selected when the user submits the
form. It works by programatically setting the list boxes to multiple,
and then selecting the controls in them:

function selectAllInLists()
{
var controlArray = new Array();
controlArray[0] = "bTelephone";
controlArray[1] = "bEmail";
controlArray[2] = "bWebsite";

for(var i=0;i<controlArray.length;i++)
{
var listWeb = document.getElementById(controlArray[i]);
listWeb.multiple = true;

for(var j=0;j<listWeb.length;j++)
{
listWeb[j].selected = true;
}
}
}

This works fine with Firefox, and most of the time in Internet
Explorer. However, if the user wants to update an existing record, and
the list boxes have more than one element (each), and the user makes no
change to the list boxes (doesn't touch them), THEN only the last item
in each list box is passed when the form is submitted. Perplexing!!
I've tried a number of hacks, such as programmatically selecting the
list box when entering the page, and adding and deleting one
programmatically. No luck.

Any pointers would be greatly appreciated!

Cheers

James

Sep 6 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ja*********@canberra.edu.au wrote:
Hi

I was wondering if anyone else had had this problem before (can't find
anything on the web about it).

I have three select elements (list boxes - from here on I'll refer to
them as 'the list boxes'). Users can add and remove items from the
list boxes.

When the users are adding and removing items, the list boxes are single
selection only. However, when the form is submitted, I want ALL items
to be submitted. So I have written the following script,which ensures
that all elements in each box are selected when the user submits the
form. It works by programatically setting the list boxes to multiple,
and then selecting the controls in them:

function selectAllInLists()
{
var controlArray = new Array();
controlArray[0] = "bTelephone";
controlArray[1] = "bEmail";
controlArray[2] = "bWebsite";
This could be written as:

var controlArray = [
"bTelephone",
"bEmail",
"bWebsite"
];

for(var i=0;i<controlArray.length;i++)
{
var listWeb = document.getElementById(controlArray[i]);
listWeb.multiple = true;

for(var j=0;j<listWeb.length;j++)
{
listWeb[j].selected = true;
}
}
}

This works fine with Firefox, and most of the time in Internet
Explorer. However, if the user wants to update an existing record, and
the list boxes have more than one element (each), and the user makes no
change to the list boxes (doesn't touch them), THEN only the last item
in each list box is passed when the form is submitted. Perplexing!!
I've tried a number of hacks, such as programmatically selecting the
list box when entering the page, and adding and deleting one
programmatically. No luck.

Any pointers would be greatly appreciated!


Have you considered writing the values to a hidden input? Then ignore
whatever values you get from the selects. You can format the value of
the hidden input to whatever suits your server parser.

If JavaScript is not available on the client you will get junk, but
since your form is already dependent on JavaScript perhaps that's not an
issue for you.
--
Rob
Sep 6 '05 #2

P: n/a
RobG wrote:
Have you considered writing the values to a hidden input? Then ignore
whatever values you get from the selects.


Like I've done here, in a library that you might be able to just plug in:
http://www.javascripttoolbox.com/optiontransfer/

Hope that helps!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 7 '05 #3

P: n/a
Thanks Rob, I did as you suggested, and it works. Still a real pain
though - I wonder if that is an identified bug?

Sep 7 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.