473,398 Members | 2,404 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,398 software developers and data experts.

Read-only properties in HTMLOptionElement objects

Below is the IDL definition of the HTMLOptionElement.

interface HTMLOptionElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute boolean defaultSelected;
readonly attribute DOMString text;
attribute long index;
attribute boolean disabled;
attribute DOMString label;
readonly attribute boolean selected;
attribute DOMString value;
};

You will notice that the 'text' and 'selected' properties are marked as
read-only. This adds an interesting dilemma: how do you go about
programatically modifying these properties, especially considering the
need to assign to 'text' when creating a new object? Would you add a text
node, as you find in HTML, to represent the text displayed? If that is the
correct approach, it still leaves 'selected' inaccessible[1].

Something that I did notice is that the ECMAScript bindings don't mark any
properties as read-only, and assigning to 'text' is possible, certainly in
Opera. Is that because there is no concept of read-only, so the browser
can choose to ignore assignments, or some other reason?
Mike

[1] I realise that you can use the 'selectedIndex' property to select
single options, but that isn't of much use when the SELECT element can
have multiple selected options.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #1
2 3380


Michael Winter wrote:
Below is the IDL definition of the HTMLOptionElement.

interface HTMLOptionElement : HTMLElement {
readonly attribute HTMLFormElement form;
attribute boolean defaultSelected;
readonly attribute DOMString text;
attribute long index;
attribute boolean disabled;
attribute DOMString label;
readonly attribute boolean selected;
attribute DOMString value;
};

You will notice that the 'text' and 'selected' properties are marked as
read-only. This adds an interesting dilemma: how do you go about
programatically modifying these properties, especially considering the
need to assign to 'text' when creating a new object? Would you add a
text node, as you find in HTML, to represent the text displayed? If that
is the correct approach, it still leaves 'selected' inaccessible[1].
The W3C DOM Level 2 HTML module at
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-70901257
contains

interface HTMLOptionElement : HTMLElement {
readonly attribute HTMLFormElement form;
// Modified in DOM Level 2:
attribute boolean defaultSelected;
readonly attribute DOMString text;
// Modified in DOM Level 2:
readonly attribute long index;
attribute boolean disabled;
attribute DOMString label;
attribute boolean selected;
attribute DOMString value;
};

You haven't told us which version you are referring to but the above is
up to date and doesn't mark the selected attribute (or property in
JavaScript terms) as readonly.
As for the text, yes, you should be able to append a text node as a
child node to set that, IE5+, Netscape 6+, Opera 7 allow that.
Something that I did notice is that the ECMAScript bindings don't
mark any properties as read-only, and assigning to 'text' is possible,
certainly in Opera. Is that because there is no concept of read-only, so
the browser can choose to ignore assignments, or some other reason?


No, I am sure Opera 7 implements some readonly requirements of the W3C
DOM HTML module, for instance try
var button = document.createElement('button');
button.type = 'reset';
and you should get an error as unfortunately the DOM even in level 2
marks that property as readonly.

I think the reason that it is possible to set text for <option> elements
is historical as browser have allowed that with
var option = new Option();
option.text = 'option text';
even before there was any W3C DOM. But of course that is a guess, only
someone at Opera can answer that for Opera, for Mozilla you might want
to search bugzilla whether text was readonly at sometime and a bug
requesting to change that for NN4 compatibility was accepted and fixed.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
On Wed, 21 Jan 2004 18:06:29 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:
Michael Winter wrote:
<snip>
You haven't told us which version you are referring to but the above is
up to date and doesn't mark the selected attribute (or property in
JavaScript terms) as readonly.
Sorry, I was referring to DOM 1 (as you probably guessed). I was going to
check if they had made any changes to Level 2.
As for the text, yes, you should be able to append a text node as a
child node to set that, IE5+, Netscape 6+, Opera 7 allow that.
I could have just tested it, but I didn't want to just assume that "if it
works here, it'll work elsewhere".
Something that I did notice is that the ECMAScript bindings don't
mark any properties as read-only, and assigning to 'text' is possible,
certainly in Opera. Is that because there is no concept of read-only,
so the browser can choose to ignore assignments, or some other reason?


No, I am sure Opera 7 implements some readonly requirements of the W3C
DOM HTML module, for instance try
var button = document.createElement('button');
button.type = 'reset';
and you should get an error as unfortunately the DOM even in level 2
marks that property as readonly.


I do. Luckly, you can use the Element.setAttribute() method.
I think the reason that it is possible to set text for <option> elements
is historical as browser have allowed that with
var option = new Option();
option.text = 'option text';
even before there was any W3C DOM.


<snip>

That was my assumption as well.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3

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

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
6
by: Steve | last post by:
Hi, I'm trying to convert a file reading loop into one using streams. The BSD OS read API returns the number of bytes read, but istream::read returns itself. How can I find out the number of...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
4
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
5
by: Thomas Christensen | last post by:
This issue has been raised a couple of times I am sure. But I have yet to find a satisfying answer. I am reading from a subprocess and this subprocess sometimes hang, in which case a call to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
0
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...
0
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...

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.