It appears my question has been asked a couple of times before, yet I still can't seem to get my code to work - even though I believe I use the very same code as the solutions to those questions.
So I am using the SimpleModal JQuery plugin to create a form in a popup window. This window contains the following HTML:
<div id="containerInfo" class='modalPopUp' style='display:none'>
<form id="frmContainerInfo" method="post" action="index.php">
<div style="border-bottom: 1px solid #000">
<h1>Test popup/h1>
</div>
<br/>
<div class='cargoInfoForm'>
<label class='cifLabel'>Location:</label>
<select id="ddlLoc" name="ddlLoc" class="cifDDL" style="width: 130">
<option value="Netherlands">Netherlands</option>
<option value="Paris">Paris</option>
<option value="Hongkong">Hongkong</option>
<option value="Tokyo">Tokyo</option>
</select>
<br/>
<label class='cifLabel'>Date:</label>
<input type="text" id="locDatePicker" name="locDatePicker" value="" class="cifInputField" style="width: 130">
<br/>
<button id="saveLocInfo" name="buttonSubmitInfo" type="submit" class="cifSaveButton">Save</button>
</div>
</form>
</div>
Then I try to send the results of this form to my PHP page upon pressing the Save button in the popup window, so I can retrieve the value of the two fields (ddLock and locDatePicker). To do this I attempt to use JQuery and Ajax, which looks like this:
<script>
$(document).ready(function()
{
$(".editDisplay-button").click(function(){
$("#containerInfo").modal();
});
$("#saveLocInfo").on("click", function(){
var locval = $("#ddlLoc").val();
var dateval = $("#locDatePicker").val();
var locvalLen = locval.length;
if(locvalLen < 4) {
$("#locval").addClass("error");
}
if(locvalLen >= 4) {
// if location lettercount is four or bigger
$("#saveLocInfo").replaceWith("<em>sending...</em>");
$.ajax({
type: 'POST',
url: 'container.php',
data: $("#frmContainerInfo").serialize(),
success: function(data) {
var $response=$(data);
alert($response.filter('#ddlLoc').text());
}
});
}
});
});
</script>
It appears the data I retrieve doesn't contain any values, because my alert doesn't show the location field value. Which I find odd considering I am mimicking working code of other people that had this problem. After this JQuery/Ajax code I try to access the values in my PHP file (though I believe I never retrieved the values to begin with), which looks like this:
<?php
$location = $_POST['ddlLoc'];
$dateFieldValue = $_POST['locDatePicker'];
echo ($location);
echo ($dateFieldValue);
?>
How can I get this to work, or alternatively, how can I retrieve the values of the input fields of my popup window's form in my PHP file?
Thanks!