I am just new to AJAX and following some tutorial on youtube but I’m stuck on some things.
So, I have this button that will get the project ID that the user wants to approve on the table:
`<button type=”submit” name=”approve” id=”<?php echo $displayapprovaldetails[‘projectid’];?>” data-toggle=”modal” data-target=”#approve_data_Modal” class=”btn btn-primary btn-sm”>Approve</button>
`
Now, I have this modal form that will ask for remarks first before approving and updating the records connected to the projectid:
“`
<div class=”modal fade” id=”approve_data_Modal” tabindex=”-1″ role=”dialog” aria-labelledby=”exampleModalLabel” aria-hidden=”true”>
<div class=”modal-dialog”>
<div class=”modal-content”>
<div class=”modal-header”>
<h5 class=”modal-title font-weight-bold text-primary” id=”exampleModalLabel”>Approve</h5>
<button class=”close” type=”button” data-dismiss=”modal” aria-label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<form method=”post” id=”approve_form”>
<div class=”modal-body”>
<label>Remarks: </label>
<textarea name=”remarks” id=”remarks” rows=”5″ class=”form-control”></textarea>
</div>
<div class=”modal-footer”>
<button class=”btn btn-secondary” type=”button” data-dismiss=”modal”>Close</button>
<button class=”btn btn-primary” type=”submit” name=”approve” id=”approve”>Confirm</button>
</form>
</div>
</div>
</div>
I have seen the difference between the insert and update and that my code is really wrong but I don’t know or still new on how it should work.
Script:
“`
<script>
$(document).ready(function(){
$(‘#approve_form’).on(‘submit’, function(event){
event.preventDefault();
if($(‘#remarks’).val() == “”)
{
alert(“Remark is required.”);
}
else
{
$.ajax({
url:”include/approve.php”,
method:”post”,
data:$(‘#approve_form’).serialize(),
success: function(data)
{
$(‘#approve_form’)[0].reset();
$(‘#approve_data_Modal’).modal(‘hide’);
}
});
}
});
});
</script>
I know that I can’t get the projectid and post it to another page since I’m not sure how to put it on the script that I’ll be needing to update the table connected to it.
I just need help on how to get the projectid at the same time the value the user will input on remarks.
Any help will be appreciated.
Thanks!