1

I have been trying to get two forms on the same page to work and the only issue i'm having is not getting the clone inputs to work, they seem to conflict with each other due to the div elements.

I have been using this tutorial as a guide: http://www.9lessons.info/2009/06/submit-multiple-forms-jquery-ajax.html

Here is the code working with one form: http://jsfiddle.net/yBdTA/

And this is what i want to achieve: http://jsfiddle.net/c4Uce/

Notice when you click on the second 'Add More' link the first input clones rather than the second.

I know i could duplicate the jQuery function for the clone to match the second form:

   $(function(){
        var removeLink = ' <a class="remove" href="#" onclick="jQuery(this).parent().slideUp(function(){ jQuery(this).remove() }); return false">remove</a>';
        jQuery('a.add').relCopy({ append: removeLink});    
    });

but i want this to be, how can i call it, dynamic? like the 9lessons guide, i can use PHP to create unique identifiers for the clone elements and want the jQuery to match the ID's,

Hope i made this clear.

Help appreciated.

Eli
  • 14,779
  • 5
  • 59
  • 77
Shoebox
  • 591
  • 2
  • 7
  • 17

1 Answers1

0

U can try it , it work to multi form

http://jsfiddle.net/yBdTA/2/

(function($) {

    function remove(){
    $('.clone').each(function(i){
           var input= $(this);
            input.find('a.remove').click(function(){
              input.remove();
           });
         });
    }

    $('form').each(function(i){
          var form = $(this);
          var removeLink = '<a class="remove" href="#">remove</a>';
          var iputclone = form.find('p.clone').append(removeLink);

          form.find('a.add').click(function(){
              iputclone.clone().insertBefore(this);
              remove();
          });
        });


})(jQuery);

Update :

iputclone.clone().insertBefore(this).find('.input').attr('value','');

//So easy, U can think a object when we start will is ifself, use it next, and next 
Mif.ComicVN
  • 87
  • 1
  • 6