tags:

views:

106

answers:

1

I need to dynamically generate radio or checkbox by jQuery.
I use the following code:

var type = "radio"; // maybe checkbox
$('<input type="'+ type +'">').attr({
            name: "ename", value: "1"
})

However, the radio generated cannot be selected in IE6(other browsers are fine). What should I do?

marcc's answer solves my problem.

+2  A: 

It's the way IE6 works, you cannot set the Name attribute on elements created dynamically.

Set the Name attribute before the attr.

$('<input type="' + type + '" name="ename">').attr('value', '1');
or even
$('<input type="' + type + '" name="ename" value="1">');

marcc
I just test it and it works.I read this post before to create the input element:http://stackoverflow.com/questions/702925/creating-dynamic-radio-button-w-jqueryI think I'll need to post response to alert people about this.
Billy