当我点击表格行时,我希望我的下拉列表中填充表格行的值,我可以通过单击行来获取简单文本框中的数据,但是当我无法填写下拉列表时点击表格行我的代码如下:
Javascript代码
<script>
function showRow(row) {
var x=row.cells;
document.getElementById("id").value = x[0].innerHTML;
document.getElementById("date").value = x[1].innerHTML;
document.getElementById("name").value = x[2].innerHTML;
document.getElementById("container").value = x[3].innerHTML;
document.getElementById("trip").value = x[4].innerHTML;
}
</script>
HTML 的
<table>
<tr>
<th>ID</th>
<th>Date</th>
<th>Customer</th>
<th>Container</th>
<th>Jobs</th>
</tr>
<tr onClick="javascript:showRow(this);">
<td><?php echo $row->cust_id;?></td>
<td><?php echo $row->cust_date;?></td>
<td><?php echo $row->c_name;?></td>
<td><?php echo $row->container_id;?></td>
<td><?php echo $row->trip_id;?></td>
</tr>
</table>
<label for="exampleInputEmail1">Date</label>
<input type="date" class="form-control col-md-2" id="date">
<label for="exampleInputEmail1">Customer</label>
<select class="form-control" name="cust" id="cust">
<?php
foreach($cust as $row) {
echo '<option value="'.$row->c_id.'">'.$row->c_name.'</option>';
}
?>
</select>