473,800 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.select edIndex;
selectedValue=w hat.options[selectedId].value;
selectedObject = document.getEle mentById(what.n ame+selectedVal ue);
selectedObject. className="";
for (optionId in what.options)
{
optionValue=wha t.options[optionId].value;
if (optionValue) {
optionObject = document.getEle mentById(what.n ame+optionValue );
if (optionId!=sele ctedId) {
optionObject.cl assName="hidden ";
}
}
}
}

Aug 3 '06 #1
3 1876
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.select edIndex;
selectedValue=w hat.options[selectedId].value;
selectedObject = document.getEle mentById(what.n ame+selectedVal ue);
selectedObject. className="";
for (optionId in what.options)
{
optionValue=wha t.options[optionId].value;
if (optionValue) {
optionObject = document.getEle mentById(what.n ame+optionValue );
if (optionId!=sele ctedId) {
optionObject.cl assName="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='showme themoney(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.getEle mentById("sbox" );
for (x=0; x < sbox.length; x++)
{
window.alert(sb ox[x].value);
}

// Show which is selected
function showmethemoney( list)
{
window.alert(li st[list.selectedIn dex].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
2173
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? Regards, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
2
5237
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 down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ============================================================================
4
2825
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" src="country_state.js"> </script>
1
8743
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 persons whenever i select the number from person dropdownlist it will call the javascript function "AdjustRowsToKidsTable"
2
2471
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 selbox = document.kickoff.regionId; selbox.options.length = 0; if (chosen == "SOD") { selbox.options = new Option('EMEA');
5
1681
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!!! function addRow() { var tbl=document.getElementById('game'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); var cell_1 = row.insertCell(0); var cell_2= row.insertCell(1);
0
9551
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,...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
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
6813
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.