2017-06-30 4 views
-1

にあるをクリックしたときに値がになるようにします。あなたは簡単にアレイを使用して画像タイムシートの印刷以下javascriptを使用して1番目のtdチェックボックスをクリックすると2番目の値を取得するにはどうすればよいですか?

enter image description here

の下で表示することができます。すべてのデータは、私がここで表形式で

を印刷しなければならなかったのアレイに来ていることは、私のHTMLコードです:

 <table class="table nonStriped" width="100%"> 
<?php 
$type = array(); 
foreach ($report as $key => $r) { 
    echo " 
        <thead> 
         <tr style='border-bottom:1px solid #DDDDDD;'> 
          <th>{$empName[$key]['name_title']} {$empName[$key]['name_first']} {$empName[$key]['name_last']}</th> 
          <th colspan=\"2\" width=\"20%\"></th> 
          <th colspan=\"2\" width=\"20%\"></th> 
         </tr> 
         <tr> 
          <th width=\"10%\" class=\"table-right-left\">Date</th> 
          <th width=\"5%\" class=\"table-right-left\">AM/PM (60m/hr)</th> 
          <th width=\"5%\" class=\"table-right-left\"></th> 
          <th width=\"15%\" class=\"table-right-left\"></th> 
          <th width=\"15%\" class=\"table-right-left\">Hours Worked (hr/100)</th> 
         </tr> 
        </thead> 
        "; 
    foreach ($r as $dataKey => $data) { 
     $day = date('l', strtotime($dataKey)) . ', ' . date('m/d/Y', strtotime($dataKey)); 
     $value = "record" . $key . strtotime($dataKey); 
     foreach ($data as $reKey => $d) { 
      if ($reKey == 'count') { 
       echo " 
           <tr> 
            <td colspan=\"4\"><input type='checkbox' name='timeAll' onchange=checkAll('$value',this);>&nbsp;$day</td> 
            <td style='text-align: center;'>$d</td> 
           </tr>"; 
      } 
     } 
     foreach ($data as $reKey => $d) { 
      if ($reKey != 'count') { 
       if ($d['approved'] == 0 && ($d['record_type'] == "in" || $d['record_type'] == "observation")) { 
        if (!in_array($d['record_type'], $type)) { 
         array_push($type, $d['record_type']); 
         $check = "<input type='checkbox' name='timeLog$key' class='$value' value='{$d['id']}'>&nbsp;&nbsp;"; 
        } else { 
         $check = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
        } 
       } else if ($d['record_type'] == "out" && $d['approved'] == 0 && (in_array("in", $type) || in_array("observation", $type))) { 
        $check = "<input type='hidden' name='out_hidden' class='out_hidden' value='{$d['id']}'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
        array_pop($type); 
       } else if ($d['approved'] == 1 && ($d['record_type'] == "in" || $d['record_type'] == "observation")) { 
        $check = "<a onclick=unApprove({$d['id']});>(unapprove)&nbsp;&nbsp;</a>"; 
       } else if ($d['record_type'] == "out" && $d['approved'] == 1) { 
        $check = "<input type='hidden' name='out_approve' class='out_approve' value='{$d['id']}'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
        array_pop($type); 
       } 

       echo " 
           <tr> 
            <td>&nbsp;&nbsp;&nbsp;$check<a title='Edit' href='/timeclock/edittimeclock/{$d['id']}' style='color: #{$d['color']}'>{$d['record_type']}</a></td> 
            <td width=\"10%\" class=\"table-right-left\">{$d['time']}</td> 
            <td width=\"5%\" class=\"table-right-left\" style='color: #{$d['color']}'>{$d['ipaddress']}</td> 
            <td width=\"15%\" class=\"table-right-left\">{$d['note']}</td> 
            <td width=\"10%\" class=\"table-right-left\"></td> 
           </tr> 
           "; 
      } 
     } 
    } 
    $total = array_sum($hours[$key]); 
    echo " 
         <tr> 
          <td><b>Total Hours</b></td> 
          <td></td> 
          <td></td> 
          <td></td> 
          <td style='text-align: center;'>$total</td> 
         </tr> 
         <tr> 
          <td><input type='button' name='approve' id='approve' value='APPROVE HOURS SELECTED' onclick=approve('$key');></td> 
          <td></td> 
          <td></td> 
          <td></td> 
          <td></td> 
         </tr>"; 
} 
?> 

マイ・タイムシートの配列は次のとおりです。

Array 
    ( 
    [1] => Array 
     ( 
      [2017-06-29] => Array 
       ( 
        [count] => 5.17 
        [58] => Array 
         ( 
          [id] => 58 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 09:30 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-29 09:30:00 
          [hrCount] => 0 
         ) 

        [68] => Array 
         ( 
          [id] => 68 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 10:00 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-29 10:00:00 
          [hrCount] => 0 
         ) 

        [59] => Array 
         ( 
          [id] => 59 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 11:30 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => out 
          [color] => FF9900 
          [approved] => 0 
          [timestamp] => 2017-06-29 11:30:00 
          [hrCount] => 2.0 
         ) 

        [62] => Array 
         ( 
          [id] => 62 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 11:45 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-29 11:45:00 
          [hrCount] => 0 
         ) 

        [63] => Array 
         ( 
          [id] => 63 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 13:15 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => out 
          [color] => 0000FF 
          [approved] => 0 
          [timestamp] => 2017-06-29 13:15:00 
          [hrCount] => 1.50 
         ) 

        [67] => Array 
         ( 
          [id] => 67 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 14:20 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-29 14:20:00 
          [hrCount] => 0 
         ) 

        [69] => Array 
         ( 
          [id] => 69 
          [empId] => 1 
          [date] => 06/29/2017 
          [time] => 16:00 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => out 
          [color] => FF9900 
          [approved] => 0 
          [timestamp] => 2017-06-29 16:00:00 
          [hrCount] => 1.67 
         ) 

       ) 

      [2017-06-30] => Array 
       ( 
        [count] => 3.67 
        [71] => Array 
         ( 
          [id] => 71 
          [empId] => 1 
          [date] => 06/30/2017 
          [time] => 09:30 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-30 09:30:00 
          [hrCount] => 0 
         ) 

        [72] => Array 
         ( 
          [id] => 72 
          [empId] => 1 
          [date] => 06/30/2017 
          [time] => 11:30 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => out 
          [color] => FF9900 
          [approved] => 0 
          [timestamp] => 2017-06-30 11:30:00 
          [hrCount] => 2.0 
         ) 

        [73] => Array 
         ( 
          [id] => 73 
          [empId] => 1 
          [date] => 06/30/2017 
          [time] => 11:40 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-30 11:40:00 
          [hrCount] => 0 
         ) 

        [74] => Array 
         ( 
          [id] => 74 
          [empId] => 1 
          [date] => 06/30/2017 
          [time] => 13:20 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => out 
          [color] => 0000FF 
          [approved] => 0 
          [timestamp] => 2017-06-30 13:20:00 
          [hrCount] => 1.67 
         ) 

        [75] => Array 
         ( 
          [id] => 75 
          [empId] => 1 
          [date] => 06/30/2017 
          [time] => 14:20 
          [ipaddress] => 127.0.0.1 
          [note] => 
          [record_type] => in 
          [color] => 009900 
          [approved] => 0 
          [timestamp] => 2017-06-30 14:20:00 
          [hrCount] => 0 
         ) 

       ) 

     ) 

) 

質問に関連していれば、コメントに記入してください。方法を見つけるのを助けてください。

+0

HTMLコードを共有してください –

+0

関連するHTMLとJSを親切に共有してください。 –

+0

@GokulanPH、htmlコードを確認してください – Angel

答えて

1
$(document).on('click', '.table', function() { 
    var value = $(this).closest('tr').find('td:eq(2)').find('out_hidden').val(); 
}); 
関連する問題