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 4 of 4
  1. #1
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts

    createElement radio name bug with IE

    Just wondering if anyone knows a work around for IE not setting the name for a radio button when using createElement

    example code

    Code:
    var elem1 = document.createElement("input");
    elem1.type = "radio";
    elem1.name = "q" + strId;
    elem1.setAttribute('name',"q" + strId); 
    elem1.value = "1";
    When you look at the code, there is no name attached to the element making it useless when you are trying to reference it.

    Now I know with IE you can do:
    Code:
    var elem1 = document.createElement("<INPUT TYPE='RADIO' NAME='q" + strId+ "' VALUE='0'>");
    But that is rather ugly solution. I am about to just do the innerHTML route to avoid all of this.

    Thanks,
    Eric
    Last edited by A1ien51; 12-20-2005 at 07:20 PM. Reason: added code tags

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Take a look at this...

    You may also want to try this script, which I have adapted from another site that mentioned this problem in IE (although I cannot find the site now and I was stupid enough to forget to place acknowledgements in the script comments... ):
    PHP Code:
    function attributeSet(elemattrbsetting)
    {
        if(
    attrb.toLowerCase()=='class' || attrb.toLowerCase()=='classname')
        {
            
    elem.className=setting;
            return;
        }
        var 
    elemAttrb elem.getAttributeNode(attrb);
        if (
    elemAttrb)
        {
            
    elemAttrb.value=setting;
        } else {
            
    elem.setAttribute(attrbsetting);
        }                

    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    I ended up using the ugly method. After much research. What an irritating time I had making those radio buttons work.

    http://www.codingforums.com/showthread.php?t=60870

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I ended up doing a little hack myself shortly after I posted this question . It is sort of the way Basscyst did it. I am on my way of being bald trying to figure this one out.

    thanks,
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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