Connecting Tech Pros Worldwide Help | Site Map

Problem changing button type in IE using Javascript

mike_solomon
Guest
 
Posts: n/a
#1: Sep 5 '08
I have a button

<input type="submit" name="Delete" value="Delete">

This code can not be changed

I want to use Javascript to change the type

I tried:

document.DetailView.Delete.type='button'

This works perfectly in Firefox

But in IE I get the error

Error: Could not get the type property. This command is not supported

How can I do this in a way that works in IE
Martin Honnen
Guest
 
Posts: n/a
#2: Sep 5 '08

re: Problem changing button type in IE using Javascript


mike_solomon wrote:
Quote:
I have a button
>
<input type="submit" name="Delete" value="Delete">
>
This code can not be changed
>
I want to use Javascript to change the type
>
I tried:
>
document.DetailView.Delete.type='button'
>
This works perfectly in Firefox
>
But in IE I get the error
>
Error: Could not get the type property. This command is not supported
>
How can I do this in a way that works in IE
Create a new input element with the necessary properties, then replace
the 'submit' button with the 'button' button.
--

Martin Honnen
http://JavaScript.FAQTs.com/
mike_solomon
Guest
 
Posts: n/a
#3: Sep 5 '08

re: Problem changing button type in IE using Javascript


On 5 Sep, 13:12, Martin Honnen <mahotr...@yahoo.dewrote:
Quote:
mike_solomon wrote:
Quote:
I have a button
>
Quote:
<input type="submit" name="Delete" value="Delete">
>
Quote:
This code can not be changed
>
Quote:
I want to use Javascript to change the type
>
Quote:
I tried:
>
Quote:
document.DetailView.Delete.type='button'
>
Quote:
This works perfectly in Firefox
>
Quote:
But in IE I get the error
>
Quote:
Error: Could not get the type property. This command is not supported
>
Quote:
How can I do this in a way that works in IE
>
Create a new input element with the necessary properties, then replace
the 'submit' button with the 'button' button.
--
>
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Sorry I not sure how to to that

Can you give me an example pls
Martin Honnen
Guest
 
Posts: n/a
#4: Sep 5 '08

re: Problem changing button type in IE using Javascript


mike_solomon wrote:
Quote:
Quote:
>Create a new input element with the necessary properties, then replace
>the 'submit' button with the 'button' button.
Quote:
Sorry I not sure how to to that
>
Can you give me an example pls
Assume you have a reference named input to the submit button:

var newInput = document.createElement('input');
newInput.type = 'button'; // that should work even with IE
newInput.name = input.name;
newInput.value = newInput.defaultValue = input.value;
input.parentNode.replaceChild(newInput, input);

--

Martin Honnen
http://JavaScript.FAQTs.com/
mike_solomon
Guest
 
Posts: n/a
#5: Sep 5 '08

re: Problem changing button type in IE using Javascript


On 5 Sep, 13:33, Martin Honnen <mahotr...@yahoo.dewrote:
Quote:
mike_solomon wrote:
Quote:
Quote:
Create a new input element with the necessary properties, then replace
the 'submit' button with the 'button' button.
Sorry I not sure how to to that
>
Quote:
Can you give me an example pls
>
Assume you have a reference named input to the submit button:
>
* *var newInput = document.createElement('input');
* *newInput.type = 'button'; // that should work even with IE
* *newInput.name = input.name;
* *newInput.value = newInput.defaultValue = input.value;
* *input.parentNode.replaceChild(newInput, input);
>
--
>
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/

Martin thats great

I have done the following

var input = document.DetailView.Delete
var newInput = document.createElement('input');
newInput.type = 'button';
newInput.name = input.name
newInput.value = newInput.defaultValue = input.value;
newInput.onclick =function fdelmsg(){alert(delmsg)};
newInput.setAttribute("class","button")
input.parentNode.replaceChild(newInput, input);

This works in Firefox & almost works in IE

The bit that doesn't work in IE is
newInput.setAttribute("class","button")

It doesn't give me an error but it doesn't change the button class
either :(
mike_solomon
Guest
 
Posts: n/a
#6: Sep 5 '08

re: Problem changing button type in IE using Javascript


On 5 Sep, 13:58, mike_solomon <g...@solomontribe.co.ukwrote:
Quote:
On 5 Sep, 13:33, Martin Honnen <mahotr...@yahoo.dewrote:
>
>
>
Quote:
mike_solomon wrote:
Quote:
>Create a new input element with the necessary properties, then replace
>the 'submit' button with the 'button' button.
Sorry I not sure how to to that
>
Quote:
Quote:
Can you give me an example pls
>
Quote:
Assume you have a reference named input to the submit button:
>
Quote:
* *var newInput = document.createElement('input');
* *newInput.type = 'button'; // that should work even with IE
* *newInput.name = input.name;
* *newInput.value = newInput.defaultValue = input.value;
* *input.parentNode.replaceChild(newInput, input);
>
Quote:
--
>
Quote:
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
>
Martin thats great
>
I have done the following
>
var input = document.DetailView.Delete
var newInput = document.createElement('input');
newInput.type = 'button';
newInput.name = input.name
newInput.value = newInput.defaultValue = input.value;
newInput.onclick =function fdelmsg(){alert(delmsg)};
newInput.setAttribute("class","button")
input.parentNode.replaceChild(newInput, input);
>
This works in Firefox & almost works in IE
>
The bit that doesn't work in IE is
newInput.setAttribute("class","button")
>
It doesn't give me an error but it doesn't change the button class
either :(
Final working solution

var input = document.DetailView.Delete
var newInput = document.createElement('input');
newInput.type = 'button';
newInput.name = input.name
newInput.value = input.value;
newInput.onclick =function fdelmsg(){alert(delmsg)};
input.parentNode.replaceChild(newInput, input);
newInput.className = 'button';
mike_solomon
Guest
 
Posts: n/a
#7: Sep 5 '08

re: Problem changing button type in IE using Javascript


On 5 Sep, 13:58, mike_solomon <g...@solomontribe.co.ukwrote:
Quote:
On 5 Sep, 13:33, Martin Honnen <mahotr...@yahoo.dewrote:
>
>
>
Quote:
mike_solomon wrote:
Quote:
>Create a new input element with the necessary properties, then replace
>the 'submit' button with the 'button' button.
Sorry I not sure how to to that
>
Quote:
Quote:
Can you give me an example pls
>
Quote:
Assume you have a reference named input to the submit button:
>
Quote:
* *var newInput = document.createElement('input');
* *newInput.type = 'button'; // that should work even with IE
* *newInput.name = input.name;
* *newInput.value = newInput.defaultValue = input.value;
* *input.parentNode.replaceChild(newInput, input);
>
Quote:
--
>
Quote:
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
>
Martin thats great
>
I have done the following
>
var input = document.DetailView.Delete
var newInput = document.createElement('input');
newInput.type = 'button';
newInput.name = input.name
newInput.value = newInput.defaultValue = input.value;
newInput.onclick =function fdelmsg(){alert(delmsg)};
newInput.setAttribute("class","button")
input.parentNode.replaceChild(newInput, input);
>
This works in Firefox & almost works in IE
>
The bit that doesn't work in IE is
newInput.setAttribute("class","button")
>
It doesn't give me an error but it doesn't change the button class
either :(
Final solution

var input = document.DetailView.Delete
var newInput = document.createElement('input');
newInput.type = 'button';
newInput.name = input.name
newInput.value = input.value;
newInput.onclick =function fdelmsg(){alert(delmsg)};
input.parentNode.replaceChild(newInput, input);
newInput.className = 'button';
Gregor Kofler
Guest
 
Posts: n/a
#8: Sep 5 '08

re: Problem changing button type in IE using Javascript


mike_solomon meinte:
Quote:
The bit that doesn't work in IE is
newInput.setAttribute("class","button")
That's because IE has its problems with setAttribute(). It's superfluous
anyway.

newInput.className = "button"; will do the job more efficiently and more
compatible.

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
hj
Guest
 
Posts: n/a
#9: Sep 6 '08

re: Problem changing button type in IE using Javascript


On Sep 5, 5:02*am, mike_solomon <g...@solomontribe.co.ukwrote:
Quote:
I have a button
>
<input type="submit" name="Delete" value="Delete">
>
This code can not be changed
>
I want to use Javascript to change the type
>
I tried:
>
document.DetailView.Delete.type='button'
>
This works perfectly in Firefox
>
But in IE I get the error
>
Error: Could not get the type property. This command is not supported
>
How can I do this in a way that works in IE
Just an FYI (the solutions in following posts were spot-on):

My guess is that IE doesn't *itself* implement any of the form
elements,
such as button, input, select, etc. Rather, it uses the underlying
Windows
controls. Those Windows control elements are immutable, so once you've
defined it in IE (by giving it a type and a name), you can't just
change
it to a different type of control simply by changing a property value.

At the time I was studying this, the rumor was that MS was considering
using browser-specific controls, rather than native Windows controls,
for
at least some such elements. But I don't know what happened with that.

This is a total pita -- if you need to change an element from one type
to
another, you need to create a new element, duplicate all the important
properties of the original, like name, id, classes and events, and
then
replace the original with the duplicate. Depending on the complexity
of
your application, this can be a *lot* more difficult than simply
changing
a single property on the original.

--

hj
Closed Thread