0

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

2
Contributors
3
Replies
31
Views
3 Years
Discussion Span
Last Post by nadiam
0

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

0

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>
0

this worked.

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

SOLVED

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.