There is a script that functions correctly when a button is clicked to submit the form. However, when I change the form to automatically post on an interval, the values in the form fields are not included in the submission.
I believe this issue is related to using the closest(form) method as the button relies on it for reference, whereas auto posting on an interval does not have this reference point. Any assistance would be greatly appreciated. Please note that my form is within a SQL while loop.
A) The script when activated by a button. B) The script when set to auto-post at intervals.
The form
<form class="updateform" action="" method="">
<input type="hidden" class="customerid" name="" value="<?php echo $customerid?>">
<a class ="test">test</a>
<div class="update"></div>
</form>
** A)**
<script>
$(document).ready(function(){
$('.test').click(function(event){
event.preventDefault();
var form = $(this).closest("form");
var field1= form.find('.customerid').val();
// URL and field data to be posted
$.post('/test4.php', {customerid:field1},
// Alert Success
function(data){
form.find('.update').html(data);
});
});
});
</script>
** B)**
<script>
$(function() {
var form = $(this).closest("form");
var field1= $('.customerid').val();
function update() {
$.post("/test4.php", {customerid:field1},
function(data){
$('.update').html(data);
});
}
setInterval(update, 3000);
update();
});
</script>