IE8 and button types

G

Gregor Kofler

Trying to create a button element in IE with type set to button. The
latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element is *not*
attached to the document tree), causes "object does not support this
action(?)" (I do run a German IE8 and it says "Aktion" not something
like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Gregor

[1] http://msdn.microsoft.com/en-us/library/ms534696(VS.85).aspx
 
E

Evertjan.

Gregor Kofler wrote on 19 nov 2009 in comp.lang.javascript:
Trying to create a button element in IE with type set to button. The
latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element is *not*
attached to the document tree), causes "object does not support this
action(?)" (I do run a German IE8 and it says "Aktion" not something
like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Supposing you use Javascript,
please show the minimal code that gives your problem.
 
R

Richard Cornford

Trying to create a button element in IE with type set to
button. The latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element
is *not* attached to the document tree), causes "object does not
support this action(?)" (I do run a German IE8 and it says
"Aktion" not something like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Button elements have always been problematic in IE, but not being able
to set the - type - property is correct according to (HTML DOM level
2) spec (it is specified as read-only), even if that is poor spec
design on a element that could have 3 types and provides no
alternative setting mechanism.

Except the Core DOM does offer setAttribute, and strangely (given IE's
odd attitude to setAttribute):-

window.onload = function(){
var el = document.createElement('BUTTON');
el.setAttribute('type', 'button');

var st = el.outerHTML;
el.innerHTML = st.replace(/</g,'&lt;').replace(/>/g,'&gt;');
document.body.appendChild(el);
};

- in IE 6 and 7, gives the impression of having created a button
element with a type of 'button'.

Richard.
 
G

Gregor Kofler

Evertjan. meinte:
Gregor Kofler wrote on 19 nov 2009 in comp.lang.javascript:
Trying to create a button element in IE with type set to button. The
latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element is *not*
attached to the document tree), causes "object does not support this
action(?)" (I do run a German IE8 and it says "Aktion" not something
like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Supposing you use Javascript,
please show the minimal code that gives your problem.

I suppose

var elem = document.createElement("button");
elem.type = "button";

should suffice.

Gregor
 
G

Gregor Kofler

Richard Cornford meinte:
Trying to create a button element in IE with type set to
button. The latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element
is *not* attached to the document tree), causes "object does not
support this action(?)" (I do run a German IE8 and it says
"Aktion" not something like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Button elements have always been problematic in IE, but not being able
to set the - type - property is correct according to (HTML DOM level
2)

I see. According to my completely unscientific test it seems, that all
other (popular) browsers allow to set the type. And agreed: it is indeed
completely idiotic to have a read only property with 3 possible states,
which cannot be set...
Except the Core DOM does offer setAttribute, and strangely (given IE's
odd attitude to setAttribute):-

Yes, that seems an alternative.

Gregor
 
E

Evertjan.

Gregor Kofler wrote on 19 nov 2009 in comp.lang.javascript:
Evertjan. meinte:
Gregor Kofler wrote on 19 nov 2009 in comp.lang.javascript:
Trying to create a button element in IE with type set to button. The
latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element is
*not* attached to the document tree), causes "object does not
support this action(?)" (I do run a German IE8 and it says "Aktion"
not something like "value" or "property").

Any ideas, for a neat workaround (maybe without try-catch)?

Supposing you use Javascript,
please show the minimal code that gives your problem.

I suppose

So you are not sure it gives your problem?

var elem = document.createElement("button");
elem.type = "button";

should suffice.

Does that give your problem?

I don't think so, it would be invisible,
as it is not set into the dom-tree.
 
G

Gregor Kofler

Evertjan. meinte:
So you are not sure it gives your problem?

It does. Though it's probably not too useful to copy excerpts from my
library.
Does that give your problem?
Yes.

I don't think so, it would be invisible,
as it is not set into the dom-tree.

It doesn't matter whether it's attached to the DOM-tree.

Fixed by replacing it with
button.setAttribute("type", "button");
which works in both IE and non-IE browsers.

Gregor
 
E

Evertjan.

Gregor Kofler wrote on 20 nov 2009 in comp.lang.javascript:
It doesn't matter whether it's attached to the DOM-tree.

Fixed by replacing it with
button.setAttribute("type", "button");
which works in both IE and non-IE browsers.

If it is not attached to the dom-tree,
how can an element be visible?
But I agree, the type can be valid without the attachment.

var elem = document.createElement('button');
elem.type = 'button'; // line 2
elem.innerText = 'blah';
//document.getElementById('anElem').appendChild(elem);
alert(elem.type) // alerts "submit" in Chrome

So elem.type seems readonly, as tested in G-Chrome.
and gives an action not supported for line 2 error for IE8

=========================

So why do you need a button type button again?

If it is not attached to the DOM
[or to a orphan form element ?],
it possibly cannot know if it is inside a <form> scope?
 
G

Gregor Kofler

Evertjan. meinte:
Gregor Kofler wrote on 20 nov 2009 in comp.lang.javascript:


If it is not attached to the dom-tree,
how can an element be visible?
But I agree, the type can be valid without the attachment.

It has nothing to do with "visibility". Creating a button it becomes
automatically a submit button, i.e. type is set to "submit" and cannot
be changed directly.
var elem = document.createElement('button');
elem.type = 'button'; // line 2
elem.innerText = 'blah';
//document.getElementById('anElem').appendChild(elem);
alert(elem.type) // alerts "submit" in Chrome

So elem.type seems readonly, as tested in G-Chrome.
and gives an action not supported for line 2 error for IE8

Yes, that's what I figured out, too.
=========================

So why do you need a button type button again?

Because I need a button button, not a submit button. Anyway, the
interesting part was, why assigning a value to the type property gives
me a "not supported action" in IE.
If it is not attached to the DOM
[or to a orphan form element ?],
it possibly cannot know if it is inside a <form> scope?

Yes, it probably wouldn't make a difference.

Gregor
 
E

Evertjan.

Gregor Kofler wrote on 20 nov 2009 in comp.lang.javascript:
Evertjan. meinte:
Gregor Kofler wrote on 20 nov 2009 in comp.lang.javascript:


If it is not attached to the dom-tree,
how can an element be visible?
But I agree, the type can be valid without the attachment.

It has nothing to do with "visibility". Creating a button it becomes
automatically a submit button, i.e. type is set to "submit" and cannot
be changed directly.
var elem = document.createElement('button');
elem.type = 'button'; // line 2
elem.innerText = 'blah';
//document.getElementById('anElem').appendChild(elem);
alert(elem.type) // alerts "submit" in Chrome

So elem.type seems readonly, as tested in G-Chrome.
and gives an action not supported for line 2 error for IE8

Yes, that's what I figured out, too.
=========================

So why do you need a button type button again?

Because I need a button button, not a submit button. Anyway, the
interesting part was, why assigning a value to the type property gives
me a "not supported action" in IE.
If it is not attached to the DOM
[or to a orphan form element ?],
it possibly cannot know if it is inside a <form> scope?

Yes, it probably wouldn't make a difference.

Indeed.

You do not need a submit button to submit a form,
as myForm.submit() will do the trick.

Evenso what function would an invisible button button have,
that cannot be done with an invisible text type input?

Or even an visible button type button, as that function could be done
wtih a submit type button that is onclick precented from submitting.

============

But I do not doubt for a moment, that this is bad programming of IE8,
as the readonly way of Chrome is a bit friendlier.
 
R

RobG

Richard Cornford meinte:
Trying to create a button element in IE with type set to
button. The latter thing is required since
"In IE8 mode, the default value is submit" [1]
However, trying to set type to "button" (even when the element
is *not* attached to the document tree), causes "object does not
support this action(?)" (I do run a German IE8 and it says
"Aktion" not something like "value" or "property").
Any ideas, for a neat workaround (maybe without try-catch)?
Button elements have always been problematic in IE, but not being able
to set the - type - property is correct according to (HTML DOM level
2)

I see. According to my completely unscientific test it seems, that all
other (popular) browsers allow to set the type. And agreed: it is indeed
completely idiotic to have a read only property with 3 possible states,
which cannot be set...
Except the Core DOM does offer setAttribute, and strangely (given IE's
odd attitude to setAttribute):-

Yes, that seems an alternative.

Another option is to use an input type=button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top