D
DBoy001
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").appendChild(this.fieldReference);
for (var i=0; i < optionsToCreate.length; i++) {
this.fieldReference.options[this.fieldReference.options.length] = new
Option(optionsToCreate[1], optionsToCreate[0]);
}
}
mySelectField.prototype.selectAll = function() {
for (var i=0; i < this.fieldReference.options.length; i++)
{
this.fieldReference.options.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>
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").appendChild(this.fieldReference);
for (var i=0; i < optionsToCreate.length; i++) {
this.fieldReference.options[this.fieldReference.options.length] = new
Option(optionsToCreate[1], optionsToCreate[0]);
}
}
mySelectField.prototype.selectAll = function() {
for (var i=0; i < this.fieldReference.options.length; i++)
{
this.fieldReference.options.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>