Hi.

i got table A(contact-names) which is where name are populated to from db and table B(guest-names) where names from table A will be appended to.

this is the js i came up with to append the names:

var msg2 = '<tr class="tr"><td><input type="text" name="GName" class="input-name" placeholder="Doubleclick on a name." size="40" readonly></td></tr>';
$('.contact-names').load('/EMS2/showUser.php');
$(".guest-names").append(msg2);

$(".contact-names tr").live("dblclick", function(){
     var name = $(this).text();
     $(".input-name").val(name);
     $(".tr").append(msg2);
     $(this).empty();    
});

as u can c the doubleclick function is missing something.

as of right now the name does append into the text box and also appends a second text box under the first (good). but then if i doubeclick on a second name it fills the first textbox as well as the second one and adds 2 empty textbox instead of just one. this is what im trying to get my head around.

i think i need to use .each() to find the next empty text box and fill that in and then add a text box or something along those lines.

maybe :

$(".contact-names tr").live("dblclick", function(){
     var name = $(this).text();
     $(".tr).each(function()
     {
        //maybe something like: ,not sure
        if($(this).find(":empty").val() == "")
        {
            $(".input-name").val(name);
            $(".tr").append(msg2);
            $(this).empty();    
        }
     });
});

TIA!

I was not able to undertand what you area trying to do... but let me explain to you what your code is doing...

// Every TR inside .contact-names will have and double click event listener
$(".contact-names tr").live("dblclick", function(){
    // Name will be any content displayed inside the row
     var name = $(this).text();
     // Every .input-name will have the value 'name', regardless of where the input is
     $(".input-name").val(name);
     // 'msg2' will be appended to every .tr
     $(".tr").append(msg2);
     // Any content inside the row clicked will be removed
     // This doesn't make much sense, because the 'msg2' appended will also be removed
     $(this).empty();    
});

sorry. really didnt explain myself properly.but its okay i finally got it to work how i wanted it to.

edit:

i used .val() == "" theres a selector : :empty which can be used as well, like $('.selector :empty')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.