ranell
ranell

Reputation: 703

Duplicate a div after changing value of select

I'm trying to to duplicate a div after changing a select like in this link : http://jsfiddle.net/ranell/mN6nm/5/ I have [object] instead of my lists :( Any idea?

Thanks

Upvotes: 0

Views: 115

Answers (2)

Travesty3
Travesty3

Reputation: 14479

Try this: (jsFiddle):

$(document).ready(function () {
    var original = $("#dvCatGr");

    $('#sctChambre').change(function() {
        var total = parseInt($(this).val());

        $('#dvCat').empty();

        for (var i = 0; i < total; i++) {
            $("#dvCat").append($(original).clone().attr("id", "dvCatGr"+ i));
        }
    });
});

Upvotes: 1

j08691
j08691

Reputation: 207983

Something like this jsFiddle example?

$('#sctChambre').change(function() {
    var total = parseInt($(this).val());
    for (i = 0; i < total; i++) {
        $('#dvCat').after($('#dvCatGr').clone().attr('id', 'c' + i));
    }
});​

Upvotes: 2

Related Questions