验证codeigniter开始日期中的开始日期和结束日期是否小于结束日期

时间:2016-09-24 05:51:52

标签: javascript php codeigniter validation date

这些在视图页面中使用请添加javascript以验证此日期我使用的是代码点火器

HTML代码:

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Mfg. date </label>
<div class="col-md-6 col-sm-6 col-xs-12 form-group has-feedback">
<input type="date" class="form-control" id="startDate" name="mfg_date" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Exp. Date </label>
<div class="col-md-6 col-sm-6 col-xs-12 form-group has-feedback">
<input type="date" class="form-control" id="endDate" name="exp_date" value="">
</div>
</div>
<input type="hidden" name="action" value="add_medicines"/>
<button type="submit" class="btn btn-success" />Add</button>

2 个答案:

答案 0 :(得分:0)

在提交按钮上尝试此操作。

function validateForm() {

    var startDate = document.getElementById("startDate").value;
    var endDate = document.getElementById("endDate").value;
    var x = new Date(startDate);
    var y = new Date(endDate);

    if (x > y) {
        alert("Start date must be less than end date!");
        document.getElementById("endDate").value="";
        return false;
    }
}

答案 1 :(得分:0)

<script>
  $("#ed_endtimedate").change(function() {
    var startDate = document.getElementById("ed_starttimedate").value;
    var endDate = document.getElementById("ed_endtimedate").value;

    if ((Date.parse(endDate) <= Date.parse(startDate))) {
      alert("End date should be greater than Start date");
      document.getElementById("ed_endtimedate").value = "";
    }
  });
</script>