当我选择日期时,我想对员工姓名进行ajax调用。我希望员工名称是客户名称,位置,从日期到日期的组合。那么如何在文本框上进行ajax调用?
<form>
<fieldset>
<div class="row">
<section class="col col-2">
<label class="select">
<select name="place1" id="parent_cat">
<option selected="" disabled="">Client Name</option>
<?php
$sql1="select * from m_client order by client_name";
$res1=mysql_query($sql1);
while($row1=mysql_fetch_array($res1)) {
?>
<option value="<?php echo $row1['a_id']; ?>"><?php echo $row1['client_name']; ?></option>
<?php }?>
</select> <i></i>
</label>
</section>
<section class="col col-2">
<label class="select">
<select name="sub_cat" id="sub_cat">
<option selected="" disabled="">Location</option>
</select>
</label>
</section>
<section class="col col-2">
<label class="input"> <i class="icon-append fa fa-calendar"></i>
<input type="text" name="f1" autocomplete="off" placeholder="From Date" id="datepicker-10" data-dateformat='dd-mm-yy'>
</label>
</section>
<section class="col col-2">
<label class="input"> <i class="icon-append fa fa-calendar"></i>
<input type="text" name="f2" autocomplete="off" placeholder="To Date" id="datepicker-11" data-dateformat='dd-mm-yy'>
</label>
</section>
<section class="col col-3">
<label class="select">
<select name="emp_name" id="emp_name">
<option selected="" disabled="">Employee Name</option>
</select>
</label>
</section>
</div>
</fieldset>
<input type="submit" name="submit" value="Submit Details" >
</form>
JavaScript代码是:
<script type="text/javascript">
$('.todate').click(function() {
var val1 = $('.client_name').val();
var val2 = $('.client_location').val();
var val3 = $('.from_date').val();
var val4 = $('.to_date').val();
$.ajax({
type: 'POST',
url: 'process.php',
data: {
text1: val1, text2: val2 , text3: val3, text4: val4 },
success: function(response) {
$('#emp_name').html(response);
}
});
});
</script>
最佳答案
如果您使用的是日期选择器,请选择日期,然后使用onSelect事件
例如
$("#dt").datepicker({
onSelect: function(dateText, inst) {
//write you ajax here
}
});