473,800 Members | 3,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

options.selecte d on select multiple

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(o ptionsToCreate) {
this.fieldRefer ence = window.document .createElement( "select");
this.fieldRefer ence.id = "myselect";
this.fieldRefer ence.multiple = true;
this.fieldRefer ence.size = 10;

window.document .getElementById ("itGoesHere"). appendChild(thi s.fieldReferenc e);

for (var i=0; i < optionsToCreate .length; i++) {

this.fieldRefer ence.options[this.fieldRefer ence.options.le ngth] = new
Option(optionsT oCreate[i][1], optionsToCreate[i][0]);
}
}
mySelectField.p rototype.select All = function() {
for (var i=0; i < this.fieldRefer ence.options.le ngth; i++)
{
this.fieldRefer ence.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.selectA ll();
</script>

Jul 28 '06 #1
4 11412

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
Jul 29 '06 #2
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...

Jul 31 '06 #3
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.fieldRefer ence = window.document .createElement( "<select
name=\"myselect \" id=\"myselect\" multiple=\"mult iple\"
size=\"10\"></select>");

Jul 31 '06 #4

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(o ptionsToCreate) {
this.fieldRefer ence = window.document .createElement( "select");
this.fieldRefer ence.id = "myselect";
this.fieldRefer ence.multiple = true;
this.fieldRefer ence.size = 10;

window.document .getElementById ("itGoesHere"). appendChild(thi s.fieldReferenc e);

for (var i=0; i < optionsToCreate .length; i++) {

this.fieldRefer ence.options[this.fieldRefer ence.options.le ngth] = new
Option(optionsT oCreate[i][1], optionsToCreate[i][0]);
}
}
mySelectField.p rototype.select All = function() {
for (var i=0; i < this.fieldRefer ence.options.le ngth; i++)
{
this.fieldRefer ence.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.selectA ll();
</script>
Kindof lame but, putting the last line in a timeout for a delay made it
work on mine.
setTimeout("myF ield.selectAll( );",10);

Jul 31 '06 #5

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

Similar topics

8
22756
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 for this is quite obvious, since the resulting html tag looks like this: <option value="go "again" selected="selected">nochmal &quot;go</option>
12
6559
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
15
15485
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 multiple> elements. Am I missing something obvious? Sincerely, TJ Walls
8
2168
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" selected>option1</option> <option value="option2" selected>option2</option> <option value="option3" selected>option3</option> </select> <input type="button"
2
11422
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 another option like menu.options.removeAttribute("selected");
4
1957
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 want to change or add options to a drop down box, I then have to copy that to the other 11 boxes. Would it be possible to define the options once, and then have all of the drop down boxes get their options from the single list? Here is my...
1
5082
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 track of the moved option's optgroup, so that if I remove it from the "target" select list, it moves back into it's respective optgroup in the "source" select list. I have things moving back and forth, but I'm not sure how to handle the optgroup...
5
3315
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.
2
2783
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 <form name="search" id="search" action= "search.php" method = "post" onreset="formReset(this);return false;"> <table cellspacing="1" cellpadding="1" > <tr> <!-- Input field for responsible-->
0
9694
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10256
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7584
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6824
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5477
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4152
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
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2953
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.