SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: IE7 radio button issue when created dynamically

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE7 radio button issue when created dynamically

    I have an issue in IE7 when I am creating clones of radio buttons. I am dynamically updating the name and ID attributes, however, I still have the issue that a radio button being checked resets any of the others which have been created dynamically. Any idea how this can fixed? Here is a fiddle of the issue

    This is the JS code which manipulates the form fields:

    Code:
    // Dropdown select
    $('#quantity').live("change", function(){
    
        $('.questions_clonable:not(.questions_clonable:first)').remove();
    
    
        // Get value of selection
        var num = $(this).val();
    
        var cloned_el = $('.questions_clonable').clone();   
    
        if (num > 1)
        {  
            for (var i = 1; i < num; i++)
            {
                // Assign cloned block to new var
                var new_block = cloned_el;  
    
                 // Store previous number for replacing with current in cloned block input fields
                    var prev = i-1;
    
                    // Update input name to make it unique
                    new_block.find('input').each(function() {     
                        this.name = this.name.replace(prev, i); 
                        this.id = this.id + i; 
                    });
    
                // Bit of a workaround needed to clone properly, reiterating class name
                $('.multiple_questions_container').append('<span class="questions_clonable hidden">'+new_block.html()+'</span>');
    
            }   
        }
    });​

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,441
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    Hi,

    It seems your question was answered on StackOverflow already: http://stackoverflow.com/questions/1...ed-dynamically

    As the first person to answer points out, it seems IE7 won't let you rename the radio buttons' name attribute.
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi,

    It seems your question was answered on StackOverflow already: http://stackoverflow.com/questions/1...ed-dynamically

    As the first person to answer points out, it seems IE7 won't let you rename the radio buttons' name attribute.
    Yes, I found the following solution after trying out a few different suggestions.

    Code:
    function setElementName(elems, name) {
            if ($.browser.msie === true){
                $(elems).each(function() {
                    this.mergeAttributes(document.createElement("<input name='" + name + "'/>"), false);
                });
            } else {
                $(elems).attr('name', name);
            }
        }

Bookmarks

Posting Permissions

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