Table Row attr() Issue

Will Davis

I'm stuck on a piece of code that calls a jQuery modul populated with a table row id. I'm about 90% sure that the error is within my jQuery code. Once I click on the button (class="view"), I get an undefined value instead of the row ID.

Thanks for any help!

Relevant section of leads_queue_a.php:

<section class="main">
     <h1>Lead Queue - Assigned Leads</h1>
     <div id="lead_wrapper_a"></div>
</section>

fill_leads_a.php:

$cond = array();
$params = array();

if ($_POST['id'] == '') {
    return;
}

if (isset($_POST['id']) && $_POST['id'] != '') {
    $userID = $_POST['id'];
}
if (!empty($userID)) {
    $cond[] = '`users`.`id` = ?';
    $params[] = "$userID";
}

$query = "SELECT `leads`.`id`, `leads`.`fname`, `leads`.`lname`, `leads`.`lead_type`, `leads`.`addr_street`, `leads`.`addr_city`, `leads`.`addr_zip`, `leads`.`phone`, `leads`.`phone_alt`, `leads`.`note`, `leads`.`created_by`, `leads`.`created` FROM `leads`,`users`,`leads_assignment`";

if (count($cond)) {
    $query .= ' WHERE ' . implode(' AND ', $cond);
}
$query .= ' AND `leads`.`id` = `leads_assignment`.`id_lead`'
        . ' AND `users`.`id` = `leads_assignment`.`id_user`';


$stmt = $db->prepare($query);
$stmt->execute($params);

//TABLE BUILDER
$lead = '';
$lead .= '<div class="leads">';
$lead .= '<table class="lead_table">';
$lead .= '<tr>';
$lead .= '<td>Customer</td>';
$lead .= '<td>Phone</td>';
$lead .= '<td>Lead Type</td>';
$lead .= '<td>Status</td>';
$lead .= '<td>Operations</td>';
$lead .= '</tr>';

foreach ($stmt->fetchAll(PDO::FETCH_OBJ) as $row) {
    $id = $row->id;
    $status = get_statusLast($id);
    $fname = $row->fname;
    $lname = $row->lname;
    $lead_type = $row->lead_type;
    $addr_street = $row->addr_street;
    $addr_city = $row->addr_city;
    $addr_zip = $row->addr_zip;
    $phone = $row->phone;
    $phone_alt = $row->phone_alt;
    $note = $row->note;
    $created_by = $row->created_by;
    $created = $row->created;

    $lead .= "<tr id='$id'>";
    $lead .= '<td>' . $fname . ' ' . $lname . '<br />' . $addr_street . '<br />' . $addr_city . ' ' . $addr_zip . '</td>';
    $lead .= '<td>' . $phone . '<br />' . $phone_alt . '</td>';
    $lead .= '<td>' . $lead_type . '</td>';
    $lead .= '<td>' . $status . '</td>';
    $lead .= '<td><button type="button" class="view" name="view">View Notes</button><br />'
            . '<button type="button" class="update" name="update">Update Status</button></td>';
}
$lead .= '</table>';
$lead .= '</div>';
$db = null;
print $lead;

Relevent section of modul.js:

$("#lead_wrapper_a").on('click', '.view', function() {
      alert($('tr', this).attr('id'));
});
PSL

Because your selction is incorrect. Use closest to get to the clicked buttons parent row (tr). Using the syntax $('tr', this) you are trying to find tr that are descendant of the button .view which is incorrect. You need to go upwards to get to the tr. this in the handler will be the button.

alert($(this).closest('tr').attr('id'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Issue with table row acting as a link

From Dev

Mysql, Issue with inserting a row into a table

From Dev

Bizzare android table row issue

From Dev

Table with dynamic row height issue

From Dev

Mysql, Issue with inserting a row into a table

From Dev

Issue with table row acting as a link

From Dev

Table with dynamic row height issue

From Dev

Programming issue with no row at position in that table

From Dev

How to get data-attr when click table row

From Dev

Issue on Drawing Highcharts From Selected Row Table

From Dev

Issue changing table row selection color

From Dev

Android Eclipse - Table Row Button - Formatting Issue

From Dev

Smart-Table row selection issue

From Dev

jQuery - issue inserting new row in html table

From Dev

Having issue deleting a html table row using jquery dataTable

From Dev

HTML Table Row nth-child Dynamic Content Issue

From Dev

Issue on Removing A Table Row Which All <td> has a Specific Class

From Dev

Decreasing table row height in Word 2011 (possibly specific issue with end of row formatting)

From Dev

datatables in javascript get row column attr

From Dev

Jquery/Javascript issue on checkbox checked add row from one table to another with input box manipulation

From Dev

issue with VBA Copy specific row/column from Word table (with merged rows) to Excel

From Dev

Bootstrap row aligning issue

From Dev

UITableView row separator issue

From Dev

Bootstrap row issue

From Dev

Bootstrap Row spacing issue

From Dev

Strange row issue

From Dev

Bootstrap 4 row issue

From Dev

JTable scroll to row issue

From Dev

table into a table row