选择所有选项不能在我的第二个下拉工作第一个下拉列表,我从数据库中获取下拉选项,而在我的第二个下拉列表我硬编码下拉选项。
<?php
include_once("connection.php");
$query="select distinct Type,typeId from mst ORDER BY Type";
$result1=mysqli_query($con,$query);
?>
<!DOCTYPE html>
<html>
<head>
<title>
Multistep Form With Checkbox
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js" type="text/javascript"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
rel="stylesheet" type="text/css" />
<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#register_form fieldset:not(:first-of-type) {
display: none;
}
</style>
<script src="multistepjsfile.js"></script>
</head>
<body>
<div class="container">
<h2>Example: Multi Step Form using jQuery, Bootstrap and PHP</h2>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="alert alert-success hide"></div>
<form id="register_form" novalidate action="form_action.php" method="post">
<fieldset>
<h2>Step 1: Select Type </h2>
<div class="form-group">
<label for="Qtype">Types*</label>
<select name="type" id="type" multiple="multiple">
<?php
foreach($result1 as $type)
{
?>
<option value="<?php echo $type['typeId']?>"><?php echo $type['Type']?></option>
<?php
}
?>
</select>
</div><br/><br/>
<input type="button" id="btnone" class="next-form btn btn-info" value="Next"/>
</fieldset>
<fieldset>
<h2> Step 2: Select Locations</h2>
<div class="form-group">
<label for="Qlocation">Locations*</label>
<select name="location[]" id="location" multiple="multiple">
</select>
</div><br/><br/>
<input type="button" name="previous" class="previous-form btn btn-default" value="Previous" />
<input type="button" name="next" class="next-form btn btn-info" value="Next" />
</fieldset>
</form>
</div>
</body>
</html>
<script type="text/javascript">
$(function () {
$('#type').multiselect({
includeSelectAllOption: true
});
});
</script>
<script type="text/javascript">
$(function () {
$('#location').multiselect({
includeSelectAllOption: true
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#btnone').click(function () {
var selected = $("#type option:selected");
var stateID = "";
selected.each(function () {
stateID += $(this).val() + ",";
});
stateID=stateID.substring(0, stateID.length - 1);
//alert(stateID);
if(stateID){
$.ajax({
type:'POST',
url:'FetchTypeN.php',
data:'state_id='+stateID,
success:function(html){
$('#location').html('');
$('#location').multiselect('destroy');
$('#location').html(html);
$('#location').multiselect('refresh');
$('#location').multiselect();
}
});
}
});
});
</script>
FetchTypeN: -
<?php
include('connection.php');
if(isset($_POST["state_id"]) && !empty($_POST["state_id"])){
if($_POST["state_id"]=='2')
{
?>
<!--<option value="00"><b>Select all</b></option>-->
<option value="03">BM</option>
<?php
}
else if($_POST["state_id"]=='1')
{
?>
<option value="06">GL</option>
<option value="07">CP</option>
<option value="08">RO</option>
<option value="09">DR</option>
<option value="10">DP</option>
<option value="11">MZ</option>
<option value="12">BP</option>
<?php
}
else
{
?>
<option value="03">BM</option>
<option value="06">GL</option>
<option value="07">CP</option>
<option value="08">RO</option>
<option value="09">DR</option>
<option value="10">DP</option>
<option value="11">MZ</option>
<option value="12">BP</option>
<?php
}
}
?>
在我的第一个下拉列表中,即键入其工作但在我的第二个下拉列表中,即位置selectall选项不存在..我正在做一些事情,请为此提供正确的代码。谢谢提前