I have a table and inside this table I run a while loop with a form. I submit this form with Ajax.
For example:
The while loop gave 5 results, so I have 5 buttons with different hidden data. When I press the first button, I get the right data back from Ajax, but when I press the other buttons, I get no result back from Ajax.
I use a table because of the search function, so I want to keep it as a table.
(function($) {
function jobDetails(e) {
var formData = $('#jobForm').serialize() //serialize data from form
$.ajax({
url: 'jobdetails.php',
dataType: 'json',
type: 'post',
data: formData,
success: function(data, textStatus) {
// success
}
});
e.preventDefault();
}
$('#jobForm').click(jobDetails);
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div class="pull-right">
<input type="text" class="search" placeholder="Wat zoekt u?" onkeydown="onkeypressed(event, this);">
</div>
<span class="counter pull-right"></span>
<table width="100%" class="table table-striped table-bordered table-hover table-bordered results" id="searchTable">
<thead>
<tr class="warning no-result">
<td colspan="4"><i class="fa fa-warning"></i> No result</td>
</tr>
</thead>
<tbody>
<?php
if(isset($_GET['search'])){
$resource_id = ($_GET['machine']);
$jobs = "SELECT * FROM ";
$stmt = $pdo->prepare($jobs);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td>
<form id="jobForm" method="post">
<input type="hidden" name="machine" value="<?php echo $resource_id; ?>">
<input type="hidden" name="base" value="<?php echo $row[" WORKORDER_BASE_ID "]; ?>">
<input type="hidden" name="lot" value="<?php echo $row[" WORKORDER_LOT_ID "]; ?>">
<input type="hidden" name="split" value="<?php echo $row[" WORKORDER_SPLIT_ID "]; ?>">
<input type="hidden" name="sub" value="<?php echo $row[" WORKORDER_SUB_ID "]; ?>">
<input type="hidden" name="seq" value="<?php echo $row[" SEQUENCE_NO "]; ?>">
<input type="hidden" name="part" value="<?php echo $row[" PART_ID "]; ?>">
<button id="jobdetails" type="button" class="btn btn-default col-lg-12">
<?php echo $row["WORKORDER_BASE_ID"]."/".$row["WORKORDER_LOT_ID"].".".$row["WORKORDER_SPLIT_ID"]."-".$row["WORKORDER_SUB_ID"].":".$row["SEQUENCE_NO"];?>
</button>
</form>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</body>