Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2004, 06:33 AM   PM User | #1
Tails
Regular Coder

 
Join Date: Nov 2002
Posts: 672
Thanks: 1
Thanked 1 Time in 1 Post
Tails is an unknown quantity at this point
setAttribute cannot change form type

I wanted to make a script to change all submit buttons in a form into type="image". But for some reason IE is popping up with "This command is not supported." Mozilla isn't displaying the image, but it displays the form name as text (no, it doesn't recognize and display the alt text). Mozilla's DOM inspector acknowledges that I changed the input's type attribute to image, and there's no javascript errors detected in the console, but it's not displaying the image. Is there a problem with the script or are there limitations of setAttribute()?

Code:
for(i=0;i<document.forms[0].length;i++)
	{
	if(document.forms[0][i].getAttribute('type')=='submit')
		{
		document.forms[0][i].setAttribute('type','image')
		document.forms[0][i].setAttribute('src','http://yoursiteurl.com/image.gif')
		document.forms[0][i].setAttribute('alt','submit')
		}
	}
Tails is offline   Reply With Quote
Old 05-07-2004, 08:34 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
try refere the forms elements otherwise

for(i=0;i<document.forms[0].elements.length;i++)
{
if(document.forms[0].elements[i].getAttribute('type')=='submit')
{
document.forms[0].elements[i].setAttribute('type','image')
document.forms[0].elements[i].setAttribute('src','http://yoursiteurl.com/image.gif')
document.forms[0].elements[i].setAttribute('alt','submit')
}
}
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 05-07-2004, 11:22 AM   PM User | #3
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
The type attribute is read only once set. Replace the elemement with a new one instead.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:57 AM.


Advertisement
Log in to turn off these ads.