3

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 http://imagik.fr/thumb/275405.jpeg

3
  • check the updated answer i.e check the link it contains code that you want Commented Jul 30, 2010 at 6:36
  • how would you like the name of the input? e.g. name="name1",name="name2".. etc.?? Commented Jul 30, 2010 at 6:48
  • @Reigel the textbob a name like "input1" and the corresponding delete button "btnDelete1" Commented Jul 30, 2010 at 6:53

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 :)
What is method fixNames() is doing in this script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.