Paul Paul - 1 year ago 65
Javascript Question

Issue getting value of php output results with jQuery

I am attempting to get the value of specific looped elements. I basically have a list of records and if I click on a record, I want to be able to obtain the value of the

of that element. The
value is binary, either 0 or 1. The issues I am running into are the following:

-The click function I created is not generating a value and the alert is not showing.

-As you can see in my
loop, I am outputting the
if it meets a certain condition. The value I need is really

Does anyone see what I can do to help my problems?

foreach ($rows as $row) {
$status = $row['status'];
$class = $status != 0 ? 'status-nonzero' : '';
if ($status == 0) {
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
$goal_date = $row['date'];
$fixed_goal_date = fixDate($goal_date);
$html = "";
$html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
$html .= '<div class="goal-box-left">';
$html .= '<div class="goal-post-status">'.$status_img. '</div>';


$('.goal-post-status').click(function (event) {
var status = $(this).val;

Answer Source

You can set status in data-attribute then read it from jQuery:


$html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
$html .= '<div class="goal-box-left">';
$html .= '<div class="goal-post-status" data-status="'.$status.'">'.$status_img. '</div>';


$("body").on("click", ".goal-post-status", function (event) {
    var status = $(this).attr("data-status");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download