When changing the select box that particular <options>
's value has to pass to PHP variable on same page. everything happening on create_post.php file, Below code is my check box for that values are getting generated from database
<select id="Category" name="Category">
<?php
$sql1 = "SELECT DISTINCT(Cat) FROM categories ORDER BY Cat ASC";
$qry1 = mysql_query($sql1,$link);
?>
<option value="" selected="">Select Category</option>
<?php
while ($row1=mysql_fetch_assoc($qry1)) {
?>
<option value="<?php echo $row1['Cat']?>"><?php echo $row1['Cat']?></option>
<?php
}
?>
</select>
then when changing the select box option that value have to print on same page.
<?php
echo "<pre>";
print_r($_REQUEST);
echo "</pre>";
if (isset($_REQUEST['Catgy'])) {
$mainCat = $_REQUEST['Catgy'];
echo $mainCat;
}
?>
Sending select box value through ajax to same page.
$(document).ready(function() {
$('#Category').change(function(){
var Category = $(this).find('option:selected').attr('value');
$.ajax({
url:'create_post.php',
data:{'Catgy':Category},
});
});
});
Out put is an empty array for print_r
and nothing for echo
. How to pass select box values when changing to PHP variable on same page?