I am trying to retrieve on server-side the value from the selected option sent using a jQuery .load() call like this:
<script type="text/javascript">
$(function () {
$("#first").change(function () {
$("#second").load('populate_section.php?year=', {first: $(this).val()});
});
});
</script>
<tr>
<td>
<select id="first" name="year">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
</tr>
<tr>
<td>
<select id="second" name="section">
</select>
</td>
</tr>
Then how I try to retrieve the value in my PHP code :
<?php
$year = $_GET['year']; // for test only
echo "<option>" . $year . "</option>";
?>
I assume here that the result will be a dropdown box with a value of whatever I chose on the first dropdown. However, it seems that var $year is empty.
Thanks.
You have not set any value for “year” GET variable in the URL.
If you need to send $(this).val() as the “year”, do it like below code.