我有两个下拉菜单。如果我从第一个下拉列表中选择数据,则应显示第二个下拉列表中的相关数据(基于所选数据)。我有一个代码。但它没有用。谢谢你提前。
我的下拉列表是:从这里我从一个下拉列表中选择数据。
<form class="form-inline" method="post" autocomplete="off">
<div class="vali-form">
<div class="col-md-6 form-group2">
<?php
include("connection.php");
$query1=mysql_query("select * from corporate_company ORDER BY c_name") or die (mysql_error());
?>
<label class="control-label">Select Company</label>
<select required name='cname1' id="cname1">
<option>Select</option>
<?php
while($row11=mysql_fetch_array($query1))
{
?>
<option value="<?php echo $row11['id'];?>"><?php echo $row11['c_name'];?></option>
<?php
}
?>
</select>
</div>
<div class="col-md-6 form-group2">
<label class='control-label'>Select Test</label>
<select id="selecttest1" name="selecttest1">
<option>Select</option>
</select>
</div>
<div class="clearfix"> </div>
</div>
<button type="submit" class="btn btn-default btn-send" name="submittestrelation">Submit</button>
</form>
我的脚本是:
<script type="text/javascript">
$(document).ready(function(){
$("#cname1").is(function(){
var cnamee1 = $(this).val();
$.ajax({
type: "POST",
url: "process-request.php",
data: "cname12="+cnamee1,
}).done(function(data){
$("#selecttest1").html(data);
});
});
});
process-request.php是:
<?php
include("connection.php");
if(isset($_POST["cname12"])){
$cname1 = $_POST["cname12"];
$query1=mysql_query("select * from corporate_details where c_name='$cname1'") or die (mysql_error());
if($cname1 !== 'Select'){
echo"<option>Select test</option>";
while($value = mysql_fetch_array($query1)) {
?>
<option value="<?php echo $value['id'];?>"><?php echo $value['c_branch'];?></option>
<?php
}
}
}
?>