我有一个采样器的表格,他从不同的海滩收集不同的沙子样本,然后填写该表格。对于每个位置,他必须填写这些条目。我已经制作了以下表格
<table width="990" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Station Number</td>
<td><input type="text" name="station_number" size="4"></td>
<td>Evidence of Runoff</td>
<td><input type="radio" name="evidence_runoff" value="No">No
<input type="radio" name="evidence_runoff" value="Yes">Yes</td>
<td># People</td>
<td>Beach
<select name="people_beach">
<option value="0">0</option>
<?php for ($b = 1; $b <= 50; $b++) {
?>
<option value="<?php echo $b; ?>"><?php echo $b; ?></option>
<?php }
?>
</select></td>
</tr>
<tr>
<td>Location</td>
<td><select name="location" >
<?php while ($row_location = mysql_fetch_assoc($rs_location)) {
?>
<option value="<?php echo $row_location['NAME']; ?>"><?php echo $row_location['NAME']; ?></option>
<?php } ?>
</select></td>
<td>Beach Vegetation</td>
<td><input type="radio" name="beach_vegetation" value="No">
No
<input type="radio" name="beach_vegetation" value="Yes">
Yes</td>
<td> </td>
<td>Water
<select name="people_water">
<option value="0">0</option>
<?php for ($b = 1; $b <= 50; $b++) {
?>
<option value="<?php echo $b; ?>"><?php echo $b; ?></option>
<?php }
?>
</select></td>
</tr>
<tr>
<td>Time Taken</td>
<td><select name="hours">
<option value="">Hour</option>
<?php
for ($x = 1; $x <= 12; $x++) {
if (substr($x, 1, 1) == "") {
$x = "0" . $x;
}
?>
<option value="<?php echo $x; ?>"><?php echo $x; ?></option>
<?php } ?>
</select>
<select name="minutes">
<option value="">Minutes</option>
<?php
for ($x = 0; $x <= 59; $x++) {
if (substr($x, 1, 1) == "") {
$x = "0" . $x;
}
?>
<option value="<?php echo $x; ?>"><?php echo $x; ?></option>
<?php } ?>
</select></td>
<td>Beach Debris</td>
<td><input type="radio" name="beach_debris" value="No">
No
<input type="radio" name="beach_debris" value="Yes">
Yes</td>
<td># Water Fowl</td>
<td><input type="text" name="water_fowl"></td>
</tr>
<tr>
<td>Water Sports non-moto.</td>
<td><input type="text" name="water_sports"> </td>
<td>Water Sports motorized</td>
<td><input type="text" name="water_sports_motor"> </td>
<td>Sand Sports or Other</td>
<td><input type="text" name="sand_sports"> </td>
</tr>
<tr>
<td>Contaminant/Discharge Sources:</td>
<td colspan="2"><textarea name="contaminant"></textarea></td>
<td>Significat events taking place on the beach</td>
<td colspan="2"><textarea name="significant_event"></textarea></td>
</tr>
</table>
现在我要搜索的是这只是一条记录。我希望在此表的底部有一个按钮,用于添加另一个样本,并通过单击将该相同的表再次添加到表单中,并为该样本创建另一个条目。一个采样器可以生成5个条目,之后我想将这些值保存在数据库中。 关于如何解决这种情况的任何想法。
答案 0 :(得分:1)
我认为您可以通过使用ajax请求来完成此操作
表单提交按钮时单击
$('.submit').click(function(e){
e.preventDefault();
$('table').each(function(){
//you can get all values
var value = $(this).children('.childclass').val();
$.post('ajax/test.html', function(data) {
});
});
});
您可以迭代每个表并获取子值并提交到数据库
答案 1 :(得分:0)
您可以尝试使用serializeArray()
,创建表单,不要忘记在字段上设置名称。
jQuery.post("yourPhp.php",
{
data: $("#form").serializeArray(),
},
function(data){
//....
}
)
编辑:
清理你的桌子,试试这个:
$("#yourTable").click(function(){
$("#yourTable input, textarea, select").each(function(){
$(this).val("");
});
});