ie javascript bug problem in this.options

T

TKapler

i got this simmple function, It stays on onChange on select and on
change it hides all objects with ID equal to select name plus the
optionvalue. It works perfectly in Opera and FF, but IE crashes because
says that options object is null

the problem is in for (optionId in what.options)
It seems that IE does NOT return the list of options, but only some
other objects: language scrollheight, istextedit, currentstyle,
document, and onmouseup

Please can you help me how can I go throuth that cycle? I need to get
the values of all options in select. Thank you

function showHide (what) {
selectedId=what.options.selectedIndex;
selectedValue=what.options[selectedId].value;
selectedObject = document.getElementById(what.name+selectedValue);
selectedObject.className="";
for (optionId in what.options)
{
optionValue=what.options[optionId].value;
if (optionValue) {
optionObject = document.getElementById(what.name+optionValue);
if (optionId!=selectedId) {
optionObject.className="hidden";
}
}
}
}
 
M

Michael Winter

On 03/08/2006 22:57, TKapler wrote:

[snip]
the problem is in for (optionId in what.options)
It seems that IE does NOT return the list of options, but only some
other objects: language scrollheight, istextedit, currentstyle,
document, and onmouseup

As you are dealing with a host object, it is up to the implementation to
determine what is enumerable and what is not.

[snip]

Why are you using a for..in iterative statement anyway? Collections
provide numeric indices; use a for statement, instead. Unless the real
issue is elsewhere, you'll have better luck.

Mike
 
D

darwinist

TKapler said:
i got this simmple function, It stays on onChange on select and on
change it hides all objects with ID equal to select name plus the
optionvalue. It works perfectly in Opera and FF, but IE crashes because
says that options object is null

the problem is in for (optionId in what.options)
It seems that IE does NOT return the list of options, but only some
other objects: language scrollheight, istextedit, currentstyle,
document, and onmouseup

Please can you help me how can I go throuth that cycle? I need to get
the values of all options in select. Thank you

function showHide (what) {
selectedId=what.options.selectedIndex;
selectedValue=what.options[selectedId].value;
selectedObject = document.getElementById(what.name+selectedValue);
selectedObject.className="";
for (optionId in what.options)
{
optionValue=what.options[optionId].value;
if (optionValue) {
optionObject = document.getElementById(what.name+optionValue);
if (optionId!=selectedId) {
optionObject.className="hidden";
}
}
}
}

Select boxes are *themselves* a collection of options, or at least can
be treated as one in firefox and ie:

<select id='sbox' onclick='showmethemoney(this)'>
<option id='1' value=0>sfljdsf</option>
<option id='2' value=1>sfljdsf</option>
<option id='3' value=2>sfljdsf</option>
</select>

<script>
// Loop through all elements
var sbox = document.getElementById("sbox");
for (x=0; x < sbox.length; x++)
{
window.alert(sbox[x].value);
}

// Show which is selected
function showmethemoney(list)
{
window.alert(list[list.selectedIndex].id + " is selected");
}
</script>

hth

http://darwinist.googlepages.com/htmldesktop.html
(A free, open-source web-based IDE, windowing system, and desktop
environment, in 31kB of html and javascript.)
 
R

Richard Cornford

Select boxes are *themselves* a collection of options,
or at least can be treated as one in firefox and ie:
<snip>

The ability to do something in one or two environments is not in itself
a reason for doing it. The - options - collection of SELECT elements is
formally specified (as a formalisation of pre-existing behaviour) so
_any_ browser claiming to implement the W3C HTML DOM standard can be
expected to support it (current or future). Relying on an observation of
a few current browsers (at the cost of standardised features) is likely
to result in code that will fail in some current browsers.

In practice both IE and Mozilla implement the - options - collection as
a reference to the SELECT element itself, so an attempt to use a for-in
loop to iterate the properties of the SELECT element will be precisely
as successful as an attempt to enumerate the properties of their -
options - collection. And looping through the indexed properties of
the - options - collection limited by its length property will work on
the - options - collection, so there is no need to substitute the SELECT
element here.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top