Click here to Skip to main content
15,883,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I want to make two drop downs for "FromTime" and "ToTime".

I have a jquery calendar on form, Now I want to show the 8am to 8pm timings in both the dropdowns with 30 min difference.

The condition is that "FromTime" should not less than the "ToTime" and FromTime should start from current time on current date means say current date is 09/16/2015 and current time is 5pm so user should not allow to select less than that time.

I know its simple but I have done with first condition but I am unable to crack the second condition. Can anyone help?

Below is my code:

JavaScript
var currentTime = new Date();
    var currenthours = parseFloat(currentTime.getHours());
    

    $("#toCollectionTime").prop("disabled", true);
    
    $("#fromCollectionTime").change(function () {
        $("#toCollectionTime").prop("disabled", false);
        var fromCollectionTime = parseFloat($("#fromCollectionTime :selected").text());
        var toCollectionTime = parseFloat($("#toCollectionTime :selected").text());
        if (fromCollectionTime < currenthours) {
            $("#fromCollectionTime").val(currenthours + ":00");
        }
        if (fromCollectionTime > toCollectionTime) {
            var localFrom = $("#fromCollectionTime :selected").text();
            $("#toCollectionTime").val(localFrom);
        }
    });
    $("#toCollectionTime").change(function () {
        var fromCollectionTime = parseFloat($("#fromCollectionTime :selected").text());
        var toCollectionTime = parseFloat($("#toCollectionTime :selected").text());
        if (toCollectionTime < fromCollectionTime) {
            var localFrom = $("#fromCollectionTime :selected").text();
            $("#toCollectionTime").val(localFrom);
        }
    });


Thanks
Posted

1 solution

I want just give you an idea, but it might be a lot of work to use it in a perfect way. But we are not afraid or difficulties, are we? :-)

Say, you select a range of some text in a usual text edit control. You are not afraid of getting "inverted" range, right? No matter what you do, you always get some valid range where starting point has the same position or less than the ending point. Why so? Just because the greater position is always considered ending point, not the other way around.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900