Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •