コードに問題があります。ユーザーがセルテーブルをクリックすると、テキスト領域が表示されます。クリックするとテキスト領域が表示されますが、常に最初のセルに表示されます。セルが表示される場所にテキスト領域を正確に表示したい。(テーブルの値はデータベースから取得されます)。
<?php
session_start();
if(!isset($_SESSION['key']))
{
header("location:index.php");
}
include"connect.php";?>
<html>
<head>
<title>All Records</title>
<style>
table{ text-align:justified;}
a {text-decoration:none;
color:black;
}
.replace {display:none;}
</style>
<script type="text/javascript">
function exchange(el){
var ie=document.all&&!document.getElementById? document.all : 0;
var toObjId=/b$/.test(el.id)? el.id.replace(/b$/,'') : el.id+'b';
var toObj=ie? ie[toObjId] : document.getElementById(toObjId);
if(/b$/.test(el.id))
toObj.innerHTML=el.value;
else{
toObj.style.width=el.offsetWidth+7+'px';
toObj.value=el.innerHTML;
}
el.style.display='none';
toObj.style.display='inline';
}
</script>
</head>
<body>
<?php
echo "<table border=1 id='records' >";
echo "<tr><th class='data' rowspan='2' ><strong>EMPLOYEE</strong></th>";
echo "<th class='data' rowspan='2'>DATE</th>
<th colspan='2'>AM</th>
<th colspan='2'>PM</th>
<th colspan='2'>OVERTIME</th></tr>";
echo "<tr>
<th>Arrival</th>
<th>Departure</th>
<th>Arrival</th>
<th>Departure</th>
<th>In</th>
<th>Out</th>
</tr>";
$query="SELECT
employee_detail.employee_code,
employee_detail.lname,
employee_detail.fname,
employee_detail.mname,
employee_record.date,
employee_record.am_in,
employee_record.am_out,
employee_record.pm_in,
employee_record.pm_out,
employee_record.over_in,
employee_record.over_out
FROM employee_detail INNER JOIN employee_record ON
employee_record.employee_code=employee_detail.employee_code ORDER BY id DESC ";
$result=mysql_query($query);
$affected=mysql_affected_rows();
while($affected>=1&&$row=mysql_fetch_array($result))
{
echo '<tr><td><a href="edit.php?id2='.$row['employee_code'].'" name="edit">';
echo $row['lname'].", ";
echo $row['fname']." ";
echo $row['mname']."</a></td>";
echo '<td>'.$row['date'].'</td>';
echo '<td><span id="itm1" onclick="exchange(this);">'.$row['am_in'].'</span>
<textarea ondblclick="exchange(this);" id="itm1b" class="replace" type="text"
value='.$row['am_in'].'></textarea></td>';
echo '<td>'.$row['am_out'].'</td>';
echo '<td>'.$row['pm_in'].'</td>';
echo '<td>'.$row['pm_out'].'</td>';
echo '<td>'.$row['over_in'].'</td>';
echo '<td>'.$row['over_out'].'</td>';
$affected--;
}
echo "</tr></table>";
?>
</body>
</html>