Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 5th, 2008, 01:05 PM
mike_solomon
Guest
 
Posts: n/a
Default Problem changing button type in IE using Javascript

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
  #2  
Old September 5th, 2008, 01:15 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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/
  #3  
Old September 5th, 2008, 01:25 PM
mike_solomon
Guest
 
Posts: n/a
Default 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
  #4  
Old September 5th, 2008, 01:35 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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/
  #5  
Old September 5th, 2008, 02:05 PM
mike_solomon
Guest
 
Posts: n/a
Default 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 :(
  #6  
Old September 5th, 2008, 02:45 PM
mike_solomon
Guest
 
Posts: n/a
Default 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';
  #7  
Old September 5th, 2008, 02:45 PM
mike_solomon
Guest
 
Posts: n/a
Default 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';
  #8  
Old September 5th, 2008, 02:45 PM
Gregor Kofler
Guest
 
Posts: n/a
Default 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
  #9  
Old September 6th, 2008, 08:05 PM
hj
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles