Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Selecting all items in a multiple select: inconsistency with Internet Explorer

Reply
Thread Tools

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

 
 
james.dixon@canberra.edu.au
Guest
Posts: n/a
 
      09-06-2005
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      09-06-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      09-07-2005
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


 
Reply With Quote
 
james.dixon@canberra.edu.au
Guest
Posts: n/a
 
      09-07-2005
Thanks Rob, I did as you suggested, and it works. Still a real pain
though - I wonder if that is an identified bug?

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer 8: C:\Program Files\Internet Explorer\iexplore.exe vs C:\Program Files (x86)\Internet Explorer\iexplore.exe Nathan Sokalski Windows 64bit 16 02-22-2010 08:31 AM
internet explorer 7 - Internet Explorer cannot display the webpag sandy j Windows 64bit 0 05-02-2009 02:12 AM
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
Is there any way to append some items to List box, without retrieving all items through AJAX? Anjan Bhowmik ASP .Net 1 02-14-2008 09:02 PM
Multiple Deauthentications causing network inconsistency =?Utf-8?B?RGFu?= Wireless Networking 3 03-13-2007 05:32 AM



Advertisments