如果我有一個包含多行的表格,並且每行都有相同的選擇框,我將如何獲取所選下拉列表的值?無論我選擇哪一行,我目前只獲得第一行的第一個值。如何在表格內的下拉列表中選擇一個值?
<form action="<?php echo $_POST['PHP_SELF'] ; ?>" method="post">
<table class="radius" id="drTable">
<tr>
<th><a href="index.php?page=donation-requests&order_by=a.dr_id&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">ID</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.lastname&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Name</a></th>
<th><a href="index.php?page=donation-requests&order_by=d.location&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Store</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.organization&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Organization</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.event_name&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Event Name</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.event_date&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Event Date</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.date_required&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Date Needed By</a></th>
<th><a href="index.php?page=donation-requests&order_by=a.date_requested&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Date Requested</a></th>
<th><a href="index.php?page=donation-requests&order_by=c.status&order_direction=<?php if($order_direction == "ASC") { echo "DESC" ; } else { echo "ASC" ; } ?>">Status</a></th>
<th class="text-center">View/Edit</th>
<th class="text-center">Delete</th>
</tr>
<?php
while($row = $result->fetch()) {
?>
<tr>
<td><?php echo $row['dr_id'] ; ?></td>
<td><?php echo $row['lastname'].", ".$row['firstname'] ; ?></td>
<td><?php echo $row['location'] ; ?></td>
<td><?php echo $row['organization'] ; ?></td>
<td><?php echo $row['event_name'] ; ?></td>
<td><?php echo date("F j, Y", $row['event_date']) ; ?></td>
<td><?php echo date("F j, Y", $row['date_required']) ; ?></td>
<td><?php echo date("F j, Y", $row['date_requested']) ; ?></td>
<td>
<select class="radius" onchange="updateStatus(<?php echo $row['dr_id']; ?>);">
<option selected="true" disabled="disabled"><?php echo $row['status'];?></option>
<?php echo statusOptions($row['status']) ; ?>
</select>
</td>
<td class="text-center"> <a href="index.php?page=donation-requests-edit&viewing_id=<?php echo $row['dr_id'] ; ?>&status=<?php echo $_GET['status'] ; ?>"><i class="fi-pencil size-24"></i></a></td>
<td class="text-center"><a href="#" onClick="deleteRequest(<?php echo $row['dr_id'] ; ?>)"><i class="fi-trash size-24"></i></a></td>
</tr>
<?php
}
?>
</table>
</form>
的jQuery:
function updateStatus(dr_id) {
var id = dr_id;
$.ajax({ //create an ajax request to load_page.php
type: "GET",
// url: "drStatus_update.php?id="+id+"&status="+status,
dataType: "html", //expect html to be returned
success: function(response){
//alert(response);
alert(status);
}
});
}
我們需要您的一些代碼示例,至少要知道問題出在哪裏。 –
使用[':eq()'](https://api.jquery.com/eq-selector/)選擇器來執行此操作。 – Mohammad