473,788 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

options or selectedIndex property works in Firefox, not IE

I have a script that is working fine in the latest version of Firefox
with no errors or warnings, but does not work in IE. I have several
select boxes that, when changed, update some text (a price) on the
page. I'm checking what value is selected with an if statement,
setting a variable, then later updating the page. Here's the code that
gives me an "Object doesn't support this property or method" in IE but
works in Firefox:

if (document.order .cpu.options[document.order. cpu.selectedInd ex].value
== "sempron300 0") {var cpu = 85;}

the form is named order, and cpu is the select box name. The
"sempron300 0" is the value I've given the option. Why is this working
in Firefox but not in Internet Explorer? Thank you in advance for your
help,
Chris

Feb 14 '06 #1
7 7751
CF*******@gmail .com wrote:
I have a script that is working fine in the latest version of Firefox
with no errors or warnings, but does not work in IE. I have several
select boxes that, when changed, update some text (a price) on the
page. I'm checking what value is selected with an if statement,
setting a variable, then later updating the page. Here's the code that
gives me an "Object doesn't support this property or method" in IE but
works in Firefox:

if (document.order .cpu.options[document.order. cpu.selectedInd ex].value
== "sempron300 0") {var cpu = 85;}
When posting code, post a minimal working example that demonstrates the
issue, or post a link. The following displays the described behaviour:
<script type="text/javascript">

function checkIt()
{
var x = document.order. cpu;
if (x.options[x.selectedIndex].value == "sempron300 0") {
var cpu = 85;
}
alert(cpu);
}

</script>

<form name="order" action="">
<div>
<select name="cpu">
<option>sempron 3000</option>
<option>blah</option>
</select>
<input type="button" value="Check value"
onclick="checkI t();">
</div>
</form>

the form is named order, and cpu is the select box name. The
"sempron300 0" is the value I've given the option. Why is this working
in Firefox but not in Internet Explorer? Thank you in advance for your
help,


I suspect that you problem is that you haven't defined a value for the
option in the source HTML. The W3C HTML spec says that if no value
attribute is provided, the value of an option its content.

<URL:http://www.w3.org/TR/html4/interact/forms.html#adef-value-OPTION>

However, IE doesn't do that. If you don't give the option a value, you
have to explicitly get the option's text property.

There are two solutions: give the option value attribute a value or use
the text attribute.

Note that the code, as posted, has no syntax errors though it could be
much more concise. In your case, the value of the option could be '85'
and the text 'Sempron3000'. Now to get a value for local variable 'cpu'
you just get the value of the selected option, e.g.
<script type="text/javascript">
function checkIt()
{
var x = document.order. cpu;
var cpu = x.options[x.selectedIndex].value;
alert(cpu);
}
</script>

<form name="order" action="">
<div>
<select name="cpu">
<option value="85">semp ron3000</option>
<option value="12">blah </option>
</select>
<input type="button" value="Check value"
onclick="checkI t();">
</div>
</form>

--
Rob
Feb 14 '06 #2
VK
CF*******@gmail .com wrote:
I have a script that is working fine in the latest version of Firefox
with no errors or warnings, but does not work in IE. I have several
select boxes that, when changed, update some text (a price) on the
page. I'm checking what value is selected with an if statement,
setting a variable, then later updating the page. Here's the code that
gives me an "Object doesn't support this property or method" in IE but
works in Firefox:


"Object doesn't support this property or method" w/o any visible reason
in IE may indicate a name conflict, because if IE's extra name space
for ID's.

Do you have by any chance a HTML element on your page with ID "order"
or "cpu"? Seems like the case.

Try explicit notation istead:

var sel = document.forms'[order'].elements['cpu'];
if (sel.options[sel.selectedInd ex].value == "sempron300 0")
{var cpu = 85;}

Feb 14 '06 #3
VK wrote:
[...]

Try explicit notation istead:

var sel = document.forms'[order'].elements['cpu'];

--------------------------^

var sel = document.forms['order'].elements['cpu'];

[...]
--
Rob
Feb 14 '06 #4
VK

RobG wrote:
VK wrote:
[...]

Try explicit notation istead:

var sel = document.forms'[order'].elements['cpu'];

--------------------------^

var sel = document.forms['order'].elements['cpu'];

[...]


Right! Thank you for correcting my typo.
P.S. Oh boy, here is comes now... :-)

Feb 14 '06 #5
I don't guess I made it clear in my first post but I did give all my
options values. The problem was that I did have span elements on the
page with the same name, however I still received the error using the
explicit notation. I tried changing the names of the spans and it
works perfectly now. Thank you very much for your help in pointing
that out.
Chris

Feb 14 '06 #6
CF*******@gmail .com wrote:
I don't guess I made it clear in my first post but I did give all my
options values. The problem was that I did have span elements on the
page with the same name
Span elements don't have a name attribute, so that is invalid HTML.

however I still received the error using the
explicit notation.


Perhaps a consequence of IE's model of making NAMEs and IDs global
variables combined with how it supports invalid HTML.

[...]
--
Rob
Feb 14 '06 #7
I just said "name", I used the id attribute. Sorry for the confusion.
I'm just glad it's fixed. Thank you,
Chris

Feb 15 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9628
by: Paul Thompson | last post by:
I am getting an odd, inscrutable error in Mozilla Firefox. When I use an array to shift focus to an element, I get the error Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://www.biostat.wustl.edu/~consult/demo/java/mainjava.js :: nclkH :: line 292" data: no] Source File: http://www.biostat.wustl.edu/~consult/demo/java/mainjava.js Line: 292
4
1884
by: Fluffy Convict | last post by:
I have found a workaround to disable certain options in an option list: var p = document.forms.elements; p.selectedIndex=-1; This works perfectly in IE - the selectedIndex becomes unclickable. It does, however, not work in FireFox. Does any body have clue why not? Any help would be greatly appreciated :)
9
2128
by: Adam | last post by:
Hey, I'm trying to write a script with two standard drop down boxes. One contains days one contains the month. I want to update the options in the days box everytime the month is changed... i.e select August, and days are filled up to 31, select September and only 30. The part where I am having difficulty is that after the onChange event has triggered and I have checked what the new month is, filling the box with relevant values is...
2
5234
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: ============================================================================
3
1874
by: TKapler | last post by:
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...
3
3027
by: sewerized | last post by:
Hello all, I'm having a problem with a user preferences form I'm creating. I want to use dynamic dropdown SELECT boxes for this so my page doesn't get cluttered with 100000 links. Since I have 10000 Options embedded in the SELECT tags, I'm using an External JS file to display them. I'm using these same Options for different SELECT tags, so they can be "re-used (or looped)", instead of writing them over and over again.
5
11959
by: jdzemke | last post by:
I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. This functionality works with a fixed set of values in the drop-down (i.e. <option value tags). Any insight would be greatly appreciated. <INPUT TYPE="text" NAME="input1" VALUE=""...
8
9672
by: grpramodkumar | last post by:
HI, function change(value,sub) { subcat = document.getElementById(sub); subcat.options.value = value; }
5
3313
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10370
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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...
1
7519
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
6750
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
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
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.