tags:

views:

83

answers:

1

Hello,

I found this great code here the Demo. I just need some change. I'd like

  • one button by line to delete the current line
  • a confirmation before delete

Could you help me ?

Thanks,

Update 1: I'd like this alt text

+1  A: 

demo

html

<form id="myForm">
    <div style="margin-bottom:4px;" class="clonedInput">
        <input type="button" class="btnDel" value="Delete" disabled="disabled" />
        <input type="text" name="input1" />
    </div>

    <div>
        <input type="button" id="btnAdd" value="add another name" />
    </div>
</form>​

jQuery

$(document).ready(function() {

    var inputs = 1; 

    $('#btnAdd').click(function() {
        $('.btnDel:disabled').removeAttr('disabled');
        var c = $('.clonedInput:first').clone(true);
            c.children(':text').attr('name','input'+ (++inputs) );
        $('.clonedInput:last').after(c);
    });

    $('.btnDel').click(function() {
        if (confirm('continue delete?')) {
            --inputs;
            $(this).closest('.clonedInput').remove();
            $('.btnDel').attr('disabled',($('.clonedInput').length  < 2));
        }
    });


});

resources

Reigel
Yes, it's that :) A small remark when you put a text in the textbox (in the first one), and you do an "add" the text is cloned too. Sorry I'm not a UI guys :)
Kris-I
here's an update... http://jsfiddle.net/vh3Js/1/ ;)
Reigel
http://jsfiddle.net/vh3Js/2/ fixed some naming bugs... ;)
Reigel
I found by myself :)
Kris-I