开发者

Validate Broken Up Time/Date jquery

开发者 https://www.devze.com 2022-12-09 19:27 出处:网络
Using this validation plugin I am trying to do a check to make sure start-date is before end-date The date is broken up into multiple drop downs.

Using this validation plugin

I am trying to do a check to make sure start-date is before end-date

The date is broken up into multiple drop downs.

here is the start date html, the end is very similar I am using jquery to populate the fields with numbers and values, also using jquery to set the start date to a certain time and end date to +5 hours ahead, with a change function (exactly like facebook)

<select name="month" id="event-month" class="select start" ></select>
                <select name="day" id="event-day" class="select start"></select>
                <select name="year" id="event-year" class="select start"></select>
                <select name="hour" id="event-hour" class="select start"></se开发者_StackOverflowlect>
                <select name="min" id="event-min" class="select start">
                    <option value="00">00</option>
                    <option value="15">15</option>
                    <option value="30">30</option>
                    <option value="45">45</option>
                </select>
                <select name="ampm" id="event-ampm" class="select">

                    <option value="am">AM</option>
                    <option value="pm">PM</option>
                </select>

Now I just need to validate it so someone who chooses a end date that is before the start date becomes invalid.


Haven't used that plugin, but are you asking about parsing and comparing dates? JavaScript's Date.parse() method returns easily-comparable epoch time and does a pretty good job with varying formats:

var dateStart = Date.parse($("#event-month").val() + "/" + $("#event-day").val() + "/" + $("#event-year").val() + " " $("#event-hour").val() + ":" + $("#event-min").val() + " " + $("#event-ampm").val());
// var dateEnd = ...
var isLessThan = dateStart < dateEnd;
0

精彩评论

暂无评论...
验证码 换一张
取 消