hey guys.

js:

$(".addGuest-btn").live("click", function(){
/*in table2*/
   var addG = $(this).parent();
   var insert = '<tr><td class="insertG"><input type="text" class="add-name" placeholder="Doubleclick on a name."></td></tr>';
   $(addG).append(insert);/*append into table2*/
    });
});

 $(".guests td").dblclick(function(){
      /*table1 td*/
      alert("double clicked!");
       var name = $(this).clone();
       $(".add-name").each(function(){
            if($(this).val() == "")
         {
        $(this).append(name);
          }
    });

addGuest function works and appends the text box. the other half of the code doesn't run. the alert for double click appears then the rest of the function doesn't run.

i tried changing

$(this).append(name)

to

  $(this).val(name);

 /*and*/

  $(this).append().val(name);

but got [object Object] in the text box.

TIA

Oh how I wish you had included the HTML as well, instead of me typing a mock table with input fields! :(

sorry :s

table1

<tbody>
    <table class="guests-name" id="guest-name">
        <thead>
            <tr>
                <th>Guest Name</th>
            </tr>
        </thead>
        <tbody  class="guests" id="guestsN">

        </tbody>
    </table>
</tbody>

table2

<table class="tables" id="tables">
     <thead><th>Tables</th></thead>
     <tbody class="table-body" id="tbl-body">
     </tbody>
</table>

this worked.

var name = $(this).clone().text();
$(".add-name").each(function(){
    $(this).val(name);
});

SOLVED

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.