0

hey guys. im trying to copy the value of a text box to another text box on button click. what i have are 2 tables: add-guest and guest-list and a left button(<) and a right button(>) in between those 2 tables. In table add-guest names are populated from database into the body of the table using .load() . say for example there are 3 names in add-guest: noreen, marzuki, sufiz. name : noreen, is clicked ($(".the-names").live("click", function()) and alert pops up : noreen then the right button, to copy to guest-list, is clicked ($("#moveright").live("click", function(){) and alert pops up : noreen then theres another alert (alert(guest_name);) to show the copied name but the pop up alert is blank. and thats the problem.

var guest_name = $("input[name=GName]").val(name).text(); result: blank pop up
var guest_name = $("input[name=GName]").val(name); result: [object][Object]

jquery :

$(".the-names").live("click", function(){
    var name = $(this).val();
    alert(name);
    var value = $(this).css('background', 'Red');
    var row = $(this).closest("tr");
    var name_row = row.css('background', 'Red');
    $("#moveright").live("click", function(){
       var row = $(this).closest("tr");
       var name_row = row.css('background', 'Red');
       alert(name);
       var guest = '<tr><td><input type="text" class="input-name" name="GName[]" size="55" readonly></td></tr><br>';
       var guest_name = $("input[name=GName]").val(name).text();
       alert(guest_name);                
    });
 });

the-names refering to the class of the input box declared in the php.

php that selects the name to be populated in add-guest table

$check = $dbh->prepare("SELECT contact_id,salutation,fname,lname FROM contact1 ORDER BY fname ASC");
$check->execute();
if($check->rowCount() > 0)
{
    $check->setFetchMode(PDO::FETCH_ASSOC);
    while($rows = $check->fetch())
    {
        $id = $rows['contact_id'];
        $salute = $rows['salutation'];
        $fname = $rows['fname'];
        $lname = $rows['lname'];

        echo 
        "<tr id='name-row'>
            <td id='primaryname'><input type='text' class='the-names' value='$salute $fname $lname' readonly size='49'></td>
        </tr>";
    }
}   

add-guest table :

<tbody>
    <table class="add-guest">
        <thead>
            <tr>
                <th>Contacts</th>
            </tr>
        </thead>
        <tbody class="contact-names">

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

guest-list table:

<tbody>
    <table class="guest-list">
        <thead>
            <tr>
                <th>Guests</th>
            </tr>
        </thead>
        <tbody class="guest-names">

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

TIA

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by AleMonteiro
0

Hello, I get it what you are trying to do, but I'd do it a little different...

Try like this:

$(".the-names").live("click", function(){   
    // Gets Ro $(this).closest("tr");

    // Class to handle if the guest was selected or unselected.
    $row.toggleClass("guest-selected"); 

    // Sets the color
    $row.css('background', $row.hasClass("guest-selected") ? 'Red' : 'White');
 });


$("#moveright").live("click", function(){ 
    // Find all rows that were selected
    $(".the-names")
        .find("tr.guest-selected")
            // Clones the rows
            .clone() // If you want to transfers the rows instead of copying, use .detach()
                // Append in the guest-selected list.
                .appendTo("guest-list");
});

Edited by AleMonteiro

This topic has been dead for over six months. 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.