473,581 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE delays in updating DOM SELECT element

Hi

I have an HTML select element in my page and it's multiple property is
disabled (one item at a time mode) but I still want to transfer all the
items in the select to the server when the form is submitted.

I'm using javascript to change the multiple property of the select
element to true and then I'm looping through each option to change its
selected property to true.

Here is the code that's executed just before the form is submitted:

var selectElement = document.getEle mentById("mySel ectElement");
selectElement.m ultiple = true;
for (var n = 0; n < selectElement.o ptions.length; n++)
{
selectElement.o ptions[n].selected = true;
}

document.forms[0].submit();

PROBLEM....

The browser is too slow in updating the renedered DOM select element on
the page from multiple=false to multiple=true. This causes the looping
code not to work correctly resulting in only the final option being
selected (which is what I'd expect if the select element were in
single-mode). You can verify this is a speed issue by inserting an
alert() between selectElement.m ultiple = true and the for loop. This
gives the browser enough time to update the page element so that the
every option is selected.

SOLUTION....

Even the slighest delay between the execution of selectElement.m ultiple
= true and the for loop will allow enough time for the browser to
update the select element, allowing each option to be sucessfully
selected in the loop:

functionA()
{
var selectElement = document.getEle mentById("mySel ectElement");
selectElement.m ultiple = true;

setTimeout("fun ctionB()", 1);
}

functionB()
{
var selectElement = document.getEle mentById("mySel ectElement");
for (var n = 0; n < selectElement.o ptions.length; n++)
{
selectElement.o ptions[n].selected = true;
}

document.forms[0].submit();
}

Only tested this on IE6.

Anyone else come accross this before? Are there any more elegant
solutions to the problem? Any other thoughts?

Cheers
Rob

May 23 '06 #1
2 2261
Rob Long wrote:
I have an HTML select element in my page and it's multiple property is
disabled (one item at a time mode) but I still want to transfer all
the items in the select to the server when the form is submitted.


Easy solution: Fix your design.
There should be no reason to ever submit unselected elements of a
single-select list. Ever.

If you built the list on the server side, you can built it again when the
user submits. Or you can store it in the session. Etc.

If it's built dynamically on the client side, then you can build up a hidden
field value as you populate the select list, and check its value on the
server side.

Changing a single select to multiple and then selecting every element just
reeks of really bad design.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 23 '06 #2
> If it's built dynamically on the client side, then you can build up a hidden
field value as you populate the select list, and check its value on the
server side.
Yeah this is the situation I have - a user can add and remove items
from the list client side.
Changing a single select to multiple and then selecting every element just
reeks of really bad design.


I hear what you're saying, but is it really that much more of a hack
than reading all the elements and populating a hidden CSV field (which
then needs to be parsed server side)? The two approaches are
functionally equivalent, and both centre around sumbitting unselected
options. I can't help but think that if there weren't this problem with
the DOM delay and if the select control had a built-in selectAll()
method then populating a hidden field and having to parse it server
side would then "reek of bad design"?

I.e. if you could do this just before submit

selectElement.m ultiple = true;
selectElement.s electAll();
form.submit();

instead of

for (var n = 0; n < selectElement.o ptions.length; n++)
{
hiddenField.val ue += selectElement.o ptions[n].value + ",";
}
form.submit();

I do see that using the select box in this way is not using it "as it
was intended to be used." However the same principle could be applied
to pretty much all web technologies ;-)

Thanks for your input tho!

May 24 '06 #3

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

Similar topics

11
16130
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT...
3
2041
by: Jan Moravec | last post by:
Hi, I have written a Java UDF for DB2 and registered it using the following params: CREATE FUNCTION arsu_bit_value ( varchar(32) for bit data, integer ) RETURNS INTEGER EXTERNAL NAME 'ch.ips.g2.db2.ch.ips.g2.db2.ARSU_BIT_VALUE!arsu_bit_value' LANGUAGE java PARAMETER STYLE db2general DETERMINISTIC NOT FENCED NOT NULL CALL NO SQL NO...
4
2597
by: Dave Taylor | last post by:
I've been using the dataset designer in Visual Studio to create typed datasets for my application by dragging over tables from the Server Explorer and dropping them into the designer. The problem is, when I modify these tables in SQL Server (typically adding fields and what not), there doesnt seem to be an easy way to update the typed...
13
5317
by: mfreeman | last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown below. All I do is loop through the records in the table and update them without making any changes. Out of 600 records, about 40 of them throw Concurrency violation errors in the update, and my GetAllColErrs function provides no output. In comparing the rows that throw...
6
4304
by: recif20002002 | last post by:
Hello I am trying to update table1 and set a new value with a condition selecting only the results for the element with the specified ID and the first one with the Date field null. The query executes but it doesn t not update the informations. I ve tried using TOP 1 and spent hours on this query but i can t get it to work. UPDATE table1...
6
13986
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
18
9805
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and view as a web page. They'll be a small delay before the entire bunch of list items converts from left-to-right to top-to-bottom order. I expected a...
10
1898
by: pmarisole | last post by:
This is the first page...... <select size="1" name="Q1_<%=i%>" onChange="calc(<%=i%>)"> <option selected value="<% =rsScores("Q1") <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option>
3
1285
by: Evan | last post by:
Hello - My script use a DB file which is written by XML, and the user load this DB file (XML tree in memory), and then do some updating about this tree, such as delete element, generate new element or move element. The thing is, my script is a cmd based program (based on module "cmd"), and there are many users would use this script at...
0
7854
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8132
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8296
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6533
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5665
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3790
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3806
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1394
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.