i'm trying to create a 2 drop down list. the second drop down changes value when the first drop down is selected. i can't seem to get the names inserted in the second drop down. this is my code
<script type='text/javascript'>
$(window).load(function(){
$("#category").change(function () {
if ($(this).data('options') === undefined) {
/*Taking an array of all options-2 and kind of embedding it on the select1*/
$(this).data('options', $('#select2 option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#select2').html(options);
//alert(options);
});
});
</script>
<form action = '' method = 'POST'>
<select name="select1" id="category">
<option><--Destinations--></option>
<?php
$destination = mysql_query("SELECT * FROM destination");
while ($row = mysql_fetch_assoc($destination))
{
$destid = $row['destination_id'];
$destname = $row['destination_name'];
echo"<option value=".$destname.">".$destname."</option>";
}
?>
</select>
<select name="items" id="select2">
<option><--Hotels--</option>
<?php
$hotel = mysql_query("SELECT * FROM hotel");
while ($row = mysql_fetch_array($hotel))
{
$hotel_location = $row['hotel_location'];
$hotel_name = $row['hotel_name'];
echo"<option value=".$hotel_location.">".$hotel_name."</option>";
}
?>
</select>
<input type = "submit" name="add">
</form>
<?php
if(isset($_POST['select1'],$_POST['items']))
{
$destination_name = $_POST['select1'];
$hotel_name = $_POST['items'];
echo $destination_name;
//echo $destination_id;
}
?>
its already outputting the hotel location but i cant seem to find a way in getting the selected hotel name. please help
try
<script type='text/javascript'>
$(window).load(function(){
$("#category").change(function () {
if ($(this).data('options') === undefined) {
/*Taking an array of all options-2 and kind of embedding it on the select1*/
$(this).data('options', $('#select2 option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#select2').html(options);
//alert(options);
});
});
</script>
<form action = '' method = 'POST'>
<select name="select1" id="category">
<option><--Destinations--></option>
<?php
$sql = "SELECT * FROM destination";
$destination = = $conn->Execute($sql);
while ($row = $destination)
{
$destid = $row['destination_id'];
$destname = $row['destination_name'];
echo"<option value=".$destname.">".$destname."</option>";
}
?>
</select>
<select name="items" id="select2">
<option><--Hotels--</option>
<?php
$sql = "SELECT * FROM hotel";
$hotel = $conn->Execute($sql);
while ($row = $hotel)
{
$hotel_location = $row['hotel_location'];
$hotel_name = $row['hotel_name'];
echo"<option value=".$hotel_location.">".$hotel_name."</option>";
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.