...

View Full Version : setAttribute cannot change form type



Tails
05-07-2004, 06:33 AM
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()?



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')
}
}

Kor
05-07-2004, 08:34 AM
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')
}
}

liorean
05-07-2004, 11:22 AM
The type attribute is read only once set. Replace the elemement with a new one instead.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum