Reputation: 1633
i have a form for a sampler who collects different samples of sand from different beaches and then fills that form. For each location he has to fill those entries. i have made the form as below
<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>
Now what i am in search of is that this is only one record. I want to have a button at the bottom of this table for ADD ANOTHER SAMPLE and by clicking on that this same table is added again to the form and another entry for the sample is made. A sampler can make 5 entries and after that i want to save those values in the database. Any Idea on How to solve this situation.
Upvotes: 0
Views: 445
Reputation: 17586
i think you can done this by using ajax request
when form submit button click
$('.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) {
});
});
});
you can iterate over each table and get children values and submit to database
Upvotes: 1
Reputation: 3246
u can try using serializeArray()
, create a form and dont forget to set a name on your fields.
jQuery.post("yourPhp.php",
{
data: $("#form").serializeArray(),
},
function(data){
//....
}
)
edit:
to clean your table, try this:
$("#yourTable").click(function(){
$("#yourTable input, textarea, select").each(function(){
$(this).val("");
});
});
Upvotes: 0