views:

36

answers:

1

Via jQuery I'm dynamically cloning an input checkbox object, and then I'm changing its name using this instruction:

row.find('[name="ACCCHB_CDARM"]').attr("name",id);

ACCCHB_CDARM is the attribute's name of object I'm cloning.

There's no problem using FireFox, but in IE it doesn't change the original value!

Is this code correct?

Thank you very much. Mirco

+1  A: 

To reproduce your error, I've written the following code, which works just fine with Internet Explorer 8.0:

<script type="text/javascript">
    $(document).ready(function(){
        var row = $('#row');
        var inp = row.find('[name="ACCCHB_CDARM"]');
        inp.attr("name","NewName");
        alert(inp.attr("name"));
    });
</script>
<div id="row">
    <input type="checkbox" name="ACCCHB_CDARM" />
</div>

NewValue is alerted after changing the name attribute to NewValue.

It looks like that on older versions of Internet Explorer, the name attribute couldn't be changed dynamically (the post dates back from the year 2005). The current MSDN documentation for name states the following:

Microsoft JScript allows the name to be changed at run time

Further down in the documentation, where some examples are shown on how to dynamically change the name attribute you'll find the following line:

This feature requires Windows Internet Explorer 7 or later

To bring my answer to the point, it looks like you're using an older version of Internet Explorer.

Giu