0
私はphpに新しいです。私は2つの選択タグを持っています。過去3日間の問題。私はjavascript phpのコードを書いており、2番目のページの名前はapi.phpです。データベースからの最初の変更時に2番目のドロップダウンで値を入力してください
<html>
<head>
<script src="js/jquery.min.js" ></script>
</head>
<body>
<form method="post" class="form-horizontal" >
<label class="col-lg-3 control-label">Category</label>
<select id="category" class="form-control" name="Category">
<option>Select Category</option>
<?php
$con=mysqli_connect("localhost","root","","keep_shopping");
$select="select * from tbl_category";
$result=mysqli_query($con,$select);
while($row=$result->fetch_assoc()){
$CategoryName=$row['CategoryName'];
$CategoryId=$row['CategoryId'];
?>
<option value="<?php echo $CategoryId;?>"><?php echo $CategoryName;?></option>
<?php
}
?>
</select>
<br />
<br />
<br />
<label class="col-lg-3 control-label">Brand</label>
<select id="brand" class="form-control" name="Brand">
<option>Select a Brand</option>
<script>
$(document).ready(function(){
alert('Change Happened');
$('#category').change(function(){
var CategoryId=$(this).val();
$.ajax({
'type':'get',
'url':'api.php',
'data':{'CategoryId':CategoryId,'btn':1},
'success':function(response){
document.getElementById("brand").innerHTML=response;
}
});
});
});
</script>
</select>
</form>
</body>
</html>
second page name is api.php
<?php
if(isset($_GET['btn'])){
$CategoryId=$_POST['CategoryId'];
$con=mysqli_connect("localhost","root","","keep_shopping");
$select=mysqli_query($con,"select * from tbl_brand where
CategoryID='$CategoryId'");
$states='<option>-SELECT CITY-</option>';
while($row=$select->fetch_assoc()){
$states.='<option
value="'.$row["BrandID"].'">'.$row["BrandName"].'</option>';
}
echo $states;
}
?>
まだjavascriptとして機能していないため、アラートも表示されません... – Ashish
変更イベントが有効かどうかを確認する方法 – Ashish