473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read-only properties in HTMLOptionEleme nt objects

Below is the IDL definition of the HTMLOptionEleme nt.

interface HTMLOptionEleme nt : 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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #1
2 3419


Michael Winter wrote:
Below is the IDL definition of the HTMLOptionEleme nt.

interface HTMLOptionEleme nt : 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 HTMLOptionEleme nt : 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.create Element('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*******@yaho o.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.create Element('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.setAttr ibute() 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.******@blueyo nder.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
9003
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 question is now, where can I find a manual that describes what the read method does with the ifstream object? I'm sitting here with my Linux/Debian machine, but I have not found any
6
3477
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 bytes actually read? What the code fragment should do is read up to 1000 bytes into a buffer, or finish early if reading failed. Just your average read loop. I have: (this is a simplified version; I know there's no detailed error
12
11665
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 currently have as a test for using std::ifstream::read(). Is there anything wrong with the way I'm getting the file? #include <vector> #include <iomanip> #include <fstream> #include <iostream>
2
3091
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 this by aggregating new content from all databases into a single indexed database and then saving a timestamp in the account database (for the current user) that tells me when the user last read items in the aggregated database.
4
3847
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 socket read after a certain delay. The logic is (I will provide a test program below): - create and connect socket
1
4000
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
4752
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 the client application establish a connection, and send data, which appears in plain, de-crypted text on the server - this works.
6
5716
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 * vector<string>. Now, use istringstream to read read each line * from the vector a word at a time.
4
2802
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 following data.bin (3 Data appended to 2 Data): 2, data0, data1, 3, data0, data1, data2
5
12869
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 read() call will block indefinite, keeping me from killing it. The folloing sample code illustrates the problem: proc = subprocess.Popen(,
0
9568
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
10007
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
9835
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...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
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
5277
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
3
2806
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.