473,394 Members | 1,785 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,394 software developers and data experts.

DOM/HTML Button Element


[This was submitted as a bug to Opera; I'm posting it here, after not
seeing mention of this in a newsgroup search]:

In HTML 4.01, a <button> element can take 1 of 3 types:

type=submit (default)
type=reset
type=button

The Javascript to create a button element dynamically is

elem = document.createElement('button');
elem.type = 'reset';

Running this code in Opera 7.54 gives the message:

"DOMException: NO_MODIFICATION_ALLOWED_ERR"

My intuition is that the official Opera.com response will be that this
is as required by the DOM spec, which lists "type" as a readonly property.
And I'll give you that, but how can the spec be correct? It refers to the
HTML 4.01 spec, which lists the 3 possible values for type; but the DOM
interface shows no other method for altering the value of type.

In other words, how do I use Javascript to create the equivalent of either

<button name="rset" type="reset">Reset Button</button>
or
<button name="push" type="button">Push Button</button>

??

For what it's worth, Mozilla makes the "type" property read/write; and
IE requires its own bizarre argument to createElement (as:

elem = document.createElement('<button type="reset" value="Reset">Reset</button>')
hj
Jul 23 '05 #1
7 2201
On 08/06/2005 00:47, Howard Jess wrote:
[This was submitted as a bug to Opera;
It isn't a bug. Just some oddness in the DOM specification.

[snip]
In HTML 4.01, a <button> element can take 1 of 3 types:
Unfortunately, the BUTTON element is all but useless due to IE's woeful
inability to use it properly. You'd be better off using the INPUT
element, which has a modifiable type property.

[snip]
My intuition is that the official Opera.com response will be that this
is as required by the DOM spec, which lists "type" as a readonly property.
And I'll give you that, but how can the spec be correct?


You should ask that on the W3C mailing lists.

Notice that in DOM 2 HTML, the INPUT element's type attribute was
modified from read-only to read/write, but the BUTTON element was not.
Either it was overlooked, or there was a reason.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
[This was submitted as a bug to Opera;
It isn't a bug. Just some oddness in the DOM specification.


Right; the "oddness" makes dynamicly created button elements a lot
less useful, though; and in Mozilla this "oddness" is ignored (type
is read/write), and in Safari, although the property isn't directly
modifiable, setAttribute('type',...) has the expected effect.

[snip]
In HTML 4.01, a <button> element can take 1 of 3 types:
Unfortunately, the BUTTON element is all but useless due to IE's woeful
inability to use it properly. You'd be better off using the INPUT
element, which has a modifiable type property.


Yes and no. If you see you're running in IE (by detecting its "woeful"
behavior, of course), there are measures you can take.

You should ask that on the W3C mailing lists.
OK, good advice.

Notice that in DOM 2 HTML, the INPUT element's type attribute was
modified from read-only to read/write, but the BUTTON element was not.
Either it was overlooked, or there was a reason.


Bummer. Does nobody use this stuff?
hj

Jul 23 '05 #3


Howard Jess wrote:
[This was submitted as a bug to Opera;


It isn't a bug. Just some oddness in the DOM specification.

Right; the "oddness" makes dynamicly created button elements a lot
less useful, though; and in Mozilla this "oddness" is ignored (type
is read/write),


At least for <input> elements I remember that originally Mozilla
followed the readonly for the type property specified in DOM Level 1
until someone file a bug complaining that that disallows dynamically
creating the different input types. It is likely that for <button>
elements the approach was similar.
So the problem is indeed with the DOM spec but of course browsers should
follow common sense and allow dynamical creation of the different types
of input and button elements, after all the DOM should allow you to
programmatically create anything that static HTML allows.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
On Wed, 08 Jun 2005 01:47:38 +0200, Howard Jess
<howard..@dhitechnologies.dot.com> wrote:
[This was submitted as a bug to Opera; I'm posting it here, after not
seeing mention of this in a newsgroup search]: The Javascript to create a button element dynamically is

elem = document.createElement('button');
elem.type = 'reset';
Running this code in Opera 7.54 gives the message:

"DOMException: NO_MODIFICATION_ALLOWED_ERR"


Good catch, thanks: the specification probably should be corrected to
allow you to set type. I have confirmed your bug report. As you mentioned
we're probably "correct" spec-wise but when the specs are inconsistent..
--
Hallvord R. M. Steen
Opera Software
http://www.opera.com/
Jul 23 '05 #5
Howard Jess wrote:
The Javascript to create a button element dynamically is
elem = document.createElement('button');
elem.type = 'reset'; .... <button name="rset" type="reset">Reset Button</button>

For what it's worth, Mozilla makes the "type" property read/write; and
IE requires its own bizarre argument to createElement (as:

elem = document.createElement('<button type="reset" value="Reset">Reset</button>')


Interesting post. I didn't try this, but what about cloning an
existing button element (of the type you desire), and then modifying
the remaining elements?

Also, I use button, when possible (ie. browser dependent), because that
way I can indicate the access key by underlining it. e.g. <button ...
accessKey=o><u>O</u>K</button>. I seem to recall that you have to be
careful about how that text changes in some browsers. Possibly it is
necessary to nest the text in a div? I forget, but just beware if you
are doing things like
Mor<u>e</u> >> changing to/from
L<u>e</u>ss <<

Csaba Gabor from Vienna

Jul 23 '05 #6


Csaba Gabor wrote:
Howard Jess wrote:
The Javascript to create a button element dynamically is
elem = document.createElement('button');
elem.type = 'reset';

...
<button name="rset" type="reset">Reset Button</button>

For what it's worth, Mozilla makes the "type" property read/write; and
IE requires its own bizarre argument to createElement (as:

elem = document.createElement('<button type="reset" value="Reset">Reset</button>')


Interesting post. I didn't try this, but what about cloning an
existing button element (of the type you desire), and then modifying
the remaining elements?


I'm not sure how you would do this; what do you mean by "an existing
button element"? What if I'm creating the entire page using Javascript?

In any case, I do have a (not very clean) workaround: a combo function that
asks for element type (and name, which has a similar problem in IE) all
at one time; this lets me code it as (for brevity here, no error checking):

function createButton(type,name) {
var div = document.createElement('div');
div.innerHTML='<button type="'+type+'" name="'+name+'"></button>';
return div.firstChild;
}

I'd rather not use the non-standard innerHTML, but it's pretty well-
supported by all DOM-ish browsers, so ...

hj
Jul 23 '05 #7
Howard Jess wrote:
Csaba Gabor wrote:
Howard Jess wrote:
For what it's worth, Mozilla makes the "type" property read/write; and
IE requires its own bizarre argument to createElement (as:

elem = document.createElement('<button type="reset"
value="Reset">Reset</button>')


Interesting post. I didn't try this, but what about cloning an
existing button element (of the type you desire), and then modifying
the remaining elements?


[...] What if I'm creating the entire page using Javascript?


Then you would have far more serious problems than this.
PointedEars
--
When you have eliminated all which is impossible, then
whatever remains, however improbable, must be the truth.
-- Sherlock Holmes
Jul 23 '05 #8

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

Similar topics

5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
4
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
4
by: Sathyaish | last post by:
I am no JavaScript progammer, and unfortunately am having to babysit an old code base that has a lot of JavaScript in it. I have two questions: (1) Can two HTML controls have the same name? It...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
5
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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...

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.