By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

ie javascript bug problem in this.options

P: n/a
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";
}
}
}
}

Aug 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Aug 3 '06 #2

P: n/a
TKapler wrote:
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.)

Aug 4 '06 #3

P: n/a
da*******@gmail.com wrote:
<snip>
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.
Aug 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.