i have a dropdown
that fill dynamic with ajax,
<select id="singer_list">
<option value='.$value.'>'.$option.'</option>
</select>
my problem is: i can't get a Value of dropdown
on the $_POST
i'm using:
$singer_name=$_POST["singer_list"];
echo $singer_name;
but $singer_name
is show nothing! how to select value of dropdown
in $_POST
?
my ajax code is :
<script type="text/javascript">
$(function(){
$("#genre_list").change(function(){
var genre_id=$("#genre_list").val();
$.ajax({
type:'POST',
url:'ajax_singer_list.php',
data:{'genre_id':genre_id},
success:(function(data){
$("#singer_list").append(data);
})
})
})
})
</script>
ajax_singer_list.php handler:
<?php
include('../db_inc.php');
$genre_id =$_POST['genre_id'];
$result = $connection->query("SELECT singer_name,singerid from singers INNER JOIN genre_singer ON singers.singerid=genre_singer.f_singer_id where f_genre_id = '$genre_id'")or die($connection->error);
while($row = $result->fetch_object()){
$singer_name = $row->singer_name;
$singer_id = $row->singerid;
echo "<option value=$singer_id>$singer_name</option>";
}
$connection->close;
?>
Apart from if you actually post etc, the first thing is:
if you want to post a <select>
, you need to give it a name, not just an 'id'.
<select id="singer_list" name="singer_list" >