Skip to content Skip to sidebar Skip to footer

Assingning Unique Id And Names?

I have a html table with one prototype row. Prototype row has few tds and each td has input element. I am trying to clone the row and assign unique ids and names. But in Fire fox n

Solution 1:

You don't needs IDs:

<label>MY Value ONE:<br /><inputclass="required email"type="text"name="myValue1[]" /></label>

Now you can clone this label as many times as needed, and it'll work.

On the server side, you can then access (for example in PHP) $_POST['myValue1'] as an array.

Solution 2:

Sorry to tell you, but everything seems fine with what you did. I tried the example you gave on IE and it seems to work.

If you inspect it with Developer Tools you still see the old id? what version of IE?

here is the code I tried:

<html><head><scriptsrc="http://code.jquery.com/jquery-1.10.1.min.js"></script><script>


$(function() {
    $("#new").click(function(e) {

        e.preventDefault();
        var d = newDate();
        var counter = d.getTime(); 
        var master = $("table.myTable");
        var prot = master.find("tr.prototype").clone();
        prot.removeClass('prototype');
        prot.addClass("contact");

        //$(prot.find("input")[0])
        prot.find("#myValue1").attr('id',"myValue1"+counter);
        prot.find("#myValue2").attr('id',"myValue2"+counter);
        prot.find("#myValue3").attr('id',"myValue3"+counter);
        prot.find("#myValue4").attr('id',"myValue4"+counter);

        prot.find("#myValue1"+counter).attr('name',"myValue1"+counter);
        prot.find("#myValue2"+counter).attr('name',"myValue2"+counter);
        prot.find("#myValue3"+counter).attr('name',"myValue3"+counter);
        prot.find("#myValue4"+counter).attr('name',"myValue4"+counter);

            jQuery('table.myTable tr:last').before(prot);
        counter++;
    });
});

</script></head><body><tableclass="myTable"><trclass="prototype"><td><labelfor="myValue1">MY Value ONE:</label><br><inputclass="required email"id="myValue1"type="text"value=""name="myValue1"></td><td><labelfor="myValue2">MY Value TWO:</label><br><inputclass="required email"id="myValue2"type="text"value=""name="myValue2"></td><td><labelfor="myValue3">MY Value THREE:</label><br><inputclass="required email"id="myValue3"type="text"value=""name="myValue3"></td><td><labelfor="myValue4">MY Value FOUR:</label><br><inputclass="required email"id="myValue4"type="text"value=""name="myValue4"></td></tr></table><inputtype="button"id="new" /></body></html>

Post a Comment for "Assingning Unique Id And Names?"