Вот мой код. Я сделал скрипт для получения значений в «list_cust_city» из выбранного элемента в «list_cust_name» через запрос в php. Я не получил никаких значений в «list_cust_city» для города. Я сделал city.php.выбранный элемент в запросе из раскрывающегося списка в php
<script>
$('#list_cust_name').change(function(){
alert("heyyy");
$.ajax({
url:'city.php',
data:{cust_name:$(this).val()},
success: function(data){
$('#list_cust_city').html(data);
}
});
});
</script>
<label style="color:#000">Name </label>
<?php
$query_name = "SELECT DISTINCT cust_name FROM customer_db ORDER BY cust_name"; //Write a query
$data_name = mysql_query($query_name); //Execute the query
?>
<select id="list_cust_name" name="list_cust_name">
<?php
while($fetch_options_name = mysql_fetch_assoc($data_name)) { //Loop all the options retrieved from the query
$customer=$fetch_options_name['cust_name'];
?>
<option value="<?php echo $fetch_options_name['cust_name']; ?>"><?php echo $fetch_options_name['cust_name']; ?></option>
<?php
}
?>
</select>
city.php
<body>
<?php
include('dbconnect.php');
db_connect();
$cust_name1=$_GET['cust_name']; //passed value of cust_name
$query_city = "SELECT DISTINCT cust_city FROM customer_db WHERE cust_name='$cust_name1'ORDER BY cust_city"; //Write a query
$data_city = mysql_query($query_city); //Execute the query
while($fetch_options_city = mysql_fetch_assoc($data_city)) { //Loop all the options retrieved from the query
?>
<option value="<?php echo $fetch_options_city['cust_city']; ?>"><?php echo $fetch_options_city['cust_city']; ?></option>
<?php
}
?>
</body>
вам нужно добавить второй выпадающий на главной странице –
в city.php ''
тег не требуется –