Hi !
I have a problem with Internet Explorer that I really can't explain.
If anyone can find a solution to this, I congratulate you...
I'm trying to have a script dynamically select all (or some) of the
options in a select field. It won't work, it will only select one
option at a time...
While I was trying to debug, I realized that if I put an alert before
the instructions, it will work !!!
I've been able to recreate the problem in a simple html file... try
this !
First run the file as it is here... one option is selected.
Then, uncomment the alert("test"); line and run it again... all
options are selected !!!!!!!
Thanks for any help...
---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<span id="itGoesHere"></span>
</body>
</html>
<script type="text/javascript">
function mySelectField(optionsToCreate) {
this.fieldReference = window.document.createElement("select");
this.fieldReference.id = "myselect";
this.fieldReference.multiple = true;
this.fieldReference.size = 10;
window.document.getElementById("itGoesHere").appen dChild(this.fieldReference);
for (var i=0; i < optionsToCreate.length; i++) {
this.fieldReference.options[this.fieldReference.options.length] = new
Option(optionsToCreate[i][1], optionsToCreate[i][0]);
}
}
mySelectField.prototype.selectAll = function() {
for (var i=0; i < this.fieldReference.options.length; i++)
{
this.fieldReference.options[i].selected = true;
}
}
var myField = new mySelectField([["1", "Test - 1"],["2", "Test -
2"],["3", "Test - 3"],["4", "Test - 4"],["5", "Test - 5"]]);
//alert("test");
myField.selectAll();
</script> 4 11391
Roughly I'd say is a runtime issue in IE, so, do the appendChild() first, and
the .multiple=true; afterwards, as for selecting options, new Option() constructor has 4
optional arguments, the last 2 are also boolean, true/false if its default state is to
selected , and true/false for current state to selected, which you can use when making the
option, instead of looping through.
Danny
Hmmm.. nope ! I've tried both Ideas and it did nothing good...
I'm wondering if there might be something I could put instead of an
alert that would cause it to magically work without requiring user
input...
Found an answer on another thread of this forum (aparently, lots of
people have experienced this). If I create the select using this
format, it'll work :
this.fieldReference = window.document.createElement("<select
name=\"myselect\" id=\"myselect\" multiple=\"multiple\"
size=\"10\"></select>");
DBoy001 wrote:
Hi !
I have a problem with Internet Explorer that I really can't explain.
If anyone can find a solution to this, I congratulate you...
I'm trying to have a script dynamically select all (or some) of the
options in a select field. It won't work, it will only select one
option at a time...
While I was trying to debug, I realized that if I put an alert before
the instructions, it will work !!!
I've been able to recreate the problem in a simple html file... try
this !
First run the file as it is here... one option is selected.
Then, uncomment the alert("test"); line and run it again... all
options are selected !!!!!!!
Thanks for any help...
---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<span id="itGoesHere"></span>
</body>
</html>
<script type="text/javascript">
function mySelectField(optionsToCreate) {
this.fieldReference = window.document.createElement("select");
this.fieldReference.id = "myselect";
this.fieldReference.multiple = true;
this.fieldReference.size = 10;
window.document.getElementById("itGoesHere").appen dChild(this.fieldReference);
for (var i=0; i < optionsToCreate.length; i++) {
this.fieldReference.options[this.fieldReference.options.length] = new
Option(optionsToCreate[i][1], optionsToCreate[i][0]);
}
}
mySelectField.prototype.selectAll = function() {
for (var i=0; i < this.fieldReference.options.length; i++)
{
this.fieldReference.options[i].selected = true;
}
}
var myField = new mySelectField([["1", "Test - 1"],["2", "Test -
2"],["3", "Test - 3"],["4", "Test - 4"],["5", "Test - 5"]]);
//alert("test");
myField.selectAll();
</script>
Kindof lame but, putting the last line in a timeout for a delay made it
work on mine.
setTimeout("myField.selectAll();",10); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Frank Ratzlow |
last post by:
Hi folks,
I have a list of entries where some entries contain the special
character (quotes) within in the string. If I try to save this
entry everything after the quotes is skipped. The reason...
|
by: Kevin Lyons |
last post by:
Hello,
I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html
I am having difficulty getting the...
|
by: TJ Walls |
last post by:
Hello All,
Is it possible to create a <select> element with no selected options? I
have tried setting the selectedIndex attribute to -1, but as far as I can
tell this only works for <select...
|
by: Matt Kruse |
last post by:
Using the latest version of Opera 8.5, this test case:
--------------------------------------------------------
<select name="sel" multiple="true" size="3">
<option value="option1"...
|
by: ahmad |
last post by:
when i used the statment
for(var i = 0; i < menu.length; i++)
{
menu.options.selected = "false";
}
to deselect all the options within a list, it surprisingly selected all
the options. I tried...
| |
by: teknoshock |
last post by:
I have created a page with multiple drop down boxes, all populated with
the same options. My problem is, for 12 dropdown boxes and 40 choices
per box, I end up with a massive file. Also, if I...
|
by: madflytom |
last post by:
Hello,
I'm trying to move the options of one select list to another select list. The "source" select list is divided into optgroups, and the "target" select list is not. I want to somehow keep...
|
by: Max |
last post by:
Is there any way to set a select-multiple type <select
multiple="multiple"with multiple selected options in scripting?
Any idea about this is appreciative.
|
by: helplakshmi |
last post by:
Hi All,
I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now.
My form
...
|
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...
|
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...
| |
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |