Get jQuery value into PHP Code
I have some data assigned in jQuery code that I need to send over to my PHP script and I m not quite sure how to do it.
I have a main page "benefit.htm" which calls a JavaScript function "getApplicantInfo()" defined in the source file "applicant_info.js". The get Applicant function then calls "selectBenefit.js" and tries to pass the value
"$(#ss_id_other").val()" to the "selectBenefit.js" file as the vaaribale "ss_num" within that file. How can this be accomplished?
Source code snippets are included
- <!-- file: "benefits.htm" -->
- ?<!DOCTYPE html>
<html>
- <head>
<title>Benefit Processing Page Social</title>
<meta charset = "utf-8">
<link rel = "stylesheet" type = "text/css" href = "css_files/divapplist.css">
- <script src="js_files/jquery-1.11.1.min.js"></script>
- <script type = "text/javascript" src = "js_files/selectBenefit.js"></script>
- <script type = "text/javascript" src = "js_files/applicant_info.js"></script>
- </head>
- <table border="0" cellpadding="10" cellspacing="1" width="900" class="tblListForm">
<tr class="listheader">
<td></td>
<td>Social Security No.</td>
<td>Last Name</td>
<td>Other Name(s)</td>
<td>Date of Birth</td>
<td>Benefit Type</td>
- </tr>
-
<tr >
<td><input type="radio" name="arr_bnft_records"
value="47"
data-app-id="37"
data-benefit-type="Funeral Grant"
data-ss-id-other="33333"
data-father-weeks=""
data-funeral-qual=""
data-last-name="Lee"
data-other-names="Brenda"
data-dob="1965-04-04"
data-sex="F"
></td>
<td>33333</td>
<td>Lee</td>
<td>Brenda</td>
<td>1965-04-04</td>
<td>Funeral Grant</td>
- </tr>
-
- <tr class="listheader">
<td colspan="6"><input type="button" id = "submit_btn2" value ="Select" onclick= "getApplicantInfo()" /></td>
</tr>
</table>
- // file: applicant_info.js
- function getApplicantInfo()
{
- $("#divMainBenefitsProcessing").slideDown();
-
$.ajax({
cache: false,
url: 'selectedBenefit.php',
type: 'GET',
cache: false,
success: function(response) {
console.log(response);
- $("#divMainBenefitsProcessing").html(response);
$("#divMainBenefitsProcessing").slideDown();
- var radioButton = $("input[name='arr_bnft_records']:checked");
if (radioButton == null || radioButton.length < 1)
alert("Please select a benefit record for processing.");
else
{
$("#ss_id_other").val(radioButton.attr("data-ss-id-other"));
$.post('selectedBenefit.php',{ss_num: $("#ss_id_other").val()});
- }
- },
beforeSend: function(){
- },
error: function(e) {
console.log(e.message);
}
});
}
- //file: selectBenefit.php
- <?php
- echo "value: " .$_POST['ss_num'] . "<br/>";
?>