以下是用户点击复选框下拉列表时的工作时间,这项工作正常。我想当用户点击像星期二的复选框现在下拉列表将处于活动状态但是用户没有从下拉列表中选择任何时间我想要提醒或者您没有选择星期二的时间错误消息。
这是我的htmlcode: -
enter code here
<div class="form-group">
<label class="add-info">WORKING HOURS:</label>
<div>
<div class="info_user_detail">
<table class="table_info1">
@foreach($days as $key=> $alldays)
<tr>
<td>
<div class="checkbox no-margin">
<label>
<input name="days[]" value="{{ $alldays }}"type="checkbox">{{ $alldays }}
</label>
</div>
</td>
<td>
<div class="time-class">
<select name="from[]"class="select-class from">
<option value="">Select</option>
@foreach($from as $froms)
<option>{{ $froms }}</option>
@endforeach
</select>
</div>
</td>
<td>
<div class="time-class">
<select name="to[]"class="select-class to">
<option value="">Select</option>
</select>
</div>
</td>
</tr>
@endforeach
</table>
</div>
</div>
和我的Jquery代码: -
enter code here
$(".time-class .from").attr("disabled",true);
$("input[type='checkbox']").on("change", function () {
if ($(this).prop("checked")) {
$(this).parents('td:first').next().find('.from').attr("disabled",false);
}
});
$(".from").on('change',function(){
var value= $(this).val();
var elem=$(this);
elem.parents('td:first').find('.loader').show();
$.ajaxSetup({
headers:
{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url:'hours',
data:{
value:value
},
type:"post",
success:function(resp)
{
if($.trim(resp))
{
elem.parents('td:first').find('.loader').hide();
elem.parents('td:first').next().find('.to').html(resp);
}
else
{
alert("Some error occured, please try again later");
}
}
});
});
我的Laravel功能: -
enter code here
public function hours(Request $request){
if($request->ajax()){
$data = $request->all();
$to = array("7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24");
$newdata = "";
$newdata .= '<option value="">Select</option>';
if(!empty($data['value'])){
foreach($to as $tos)
{
if($tos > $data['value']){
$tos1 = $tos >= 12 ? ":00 PM" : ":00 AM" ;
$newdata .= '<option value="'.$tos.'">'.$tos.' '. $tos1.' </option>';
}
}
}
echo $newdata;die;
}
}
我正在使用Laravel框架。请帮助我。谢谢你们:)