/    Sign up×
Community /Pin to ProfileBookmark

AJAX, PHP & JAVASCRIPT: How to get the ID and input variable on modal form

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!

to post a comment
JavaPHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ElvinasApr 20.2020 — Have you figured that out already?
×

Success!

Help @larraine06 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...