在Select2 Box中,根据选择的ID,系统必须相互比较一些数据。 例如: 在市场中,客户可以为其物业购买一些套餐。 每个属性都有一个包。在Property Package中具有packagePosition数据。从SelectBox中选择属性时,如果选择了Property Package的packagePosition>任何Package的packagePosition,则系统必须给出如下错误: 该属性不适用于此软件包。 如何在Ajax或Javascript中做到这一点?
查看代码:
<?php
foreach($all_packs as $get) { ## This is showing All Packages in Market. ?>
<fieldset class="mb-3" <?php if($get->packageType == 2){echo'hidden';}?>>
<legend class="text-uppercase font-size-sm font-weight-bold"></legend>
<div class="form-group">
<label><?php echo $this->lang->line('packages_package_choose_property'); ?>:</label>
<select id="propertyDetector" class="form-control select-search" name="estateId" data-fouc>
<optgroup label="<?php echo $this->lang->line('dashboard_properties'); ?>">
<option value=""><?php echo $this->lang->line('general_select'); ?></option>
<?php foreach ($estateList as $estate) { if ($estate->estateStatus == 1) { ## This is showing All Properties of Customer in Market for buying available Package to his Property. ?>
<option value="<?php echo $estate->estateId; ?>" <?php if($estate->packagePosition < $get->packagePosition && $estate->estatePackage != '') {echo 'disabled';}?>><?php if($this->session->userdata('people_lang') == 'en') {echo $estate->estateTypeEng;} elseif($this->session->userdata('people_lang') == 'ar') {echo $estate->estateTypeAr;} ?> | <?php echo $estate->cityName. ' | ' .$estate->estateAddress ?></option>
<?php } } ?>
</optgroup>
</select>
</div>
</fieldset>
<span id="error">This Package Not Available to your Property</div>
<?php } ?>
我的Javascript代码:
$(document).ready(function(){
$('#propertyDetector').addClass('input_error');
$('#error').show();
$('#propertyDetector').change(function () {
var selectedValue = $(this).val();
if (selectedValue == <?php echo $get->packagePosition < $estate->packagePosition) {
$(this).addClass('input_error');
$('#error').show();
}else{
$(this).removeClass('input_error'); //remove class
$('#error').hide();//hide error message
}
});
});