473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ie javascript bug problem in this.options

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
3 1834
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: beguigne | last post by:
Below is a snippet of a crude date picking routine for a form. I am a novice at this so, I am hitting my head at why when I select the day, the onChange event gives me a blank. What am I missing?...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
1
by: senthilnathan1985 | last post by:
sir, am implementing javascript in my project am begineer to javascript and asp.net can you please help me for the following queries here am using one dropdownlist which contains number of...
2
by: sailajapotha | last post by:
I have one javascript code with me,to show parent dropdown as well as child dropdown. <html> <head> <script type="text/javascript" language="javascript"> function setOptions(chosen) { var...
5
by: traineeirishprogrammer | last post by:
I am currently learning javascript and DOM. Basically I am currently writing a function to add rows to a table and I am trying to do it using DOM. Each row is made up of 4 cells. Here is the code!!!...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.