473,549 Members | 2,784 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 2256
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
16098
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
2036
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
2596
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
5312
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
4299
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
13981
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
9798
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
1893
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
1284
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
7518
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
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
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...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.