I am using the JQuery Chosen Plugin to fancy up my select options. The Plugin itself is working fine. However some of my dropdowns use AJAX POST to filter / pull back a refined list of options in another Select.
The JQuery Plugin, is added and not changed. But for some reason when I select an option in a Select that filters a secondary select, the secondary select doesnt seem to recognise that an option has been selected.
Any ideas? Has anyone come across this issue before?
<div class="search-line">
<div class="search-option">
<label>Asset Type:</label>
<select name="AssetType" id="AssetType">
<?php
$type_sql = "SELECT DISTINCT AssetType.AssetTypeTitle AS HardwareAssetAssetTypeTitle, HardwareAssetAssetTypeID FROM HardwareAsset INNER JOIN AssetType ON (AssetType.AssetTypeID = HardwareAsset.HardwareAssetAssetTypeID) ORDER BY HardwareAssetAssetTypeTitle ASC";
$type = sqlsrv_query($database_connection, $type_sql);
if (!sqlsrv_has_rows($type)){
echo "<option>No Records Found</option>";
}
else{
echo "<option value= ''>Select Asset Type</option>";
while($type_option = sqlsrv_fetch_object($type)){
echo "<option value='$type_option->HardwareAssetAssetTypeID'>".$type_option->HardwareAssetAssetTypeTitle."</option>";
}
}
?>
</select>
</div>
<div class="search-option">
<label>Asset Sub-Type:</label>
<select name="AssetSubType" id="AssetSubType">
<option value="">Select Asset Type First</option>
</select>
</div>
</div>
AJAX:
$('#AssetType').on('change',function(){
var AssetAssetTypeID = $(this).val();
if(AssetAssetTypeID != 0){
$.ajax({
type:'POST',
url:'/ITSMIS/data/asset/search.php',
data:'AssetAssetTypeID='+AssetAssetTypeID,
success:function(data){
$('#AssetSubType').html(data);
}
});
}
else{
$('#AssetSubType').html('<option value="">Select Asset Type First</option>');
}
});
I have had this before, not sure why but doing the onchange like below works for me:
$('body').on('change','#AssetType',function(){
var AssetAssetTypeID = $(this).val();
if(AssetAssetTypeID != 0){
$.ajax({
type:'POST',
url:'/ITSMIS/data/asset/search.php',
data:'AssetAssetTypeID='+AssetAssetTypeID,
success:function(data){
$('#AssetSubType').html(data);
}
});
}
else{
$('#AssetSubType').html('<option value="">Select Asset Type First</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.