开发者

Jquery dependent drop down boxes populate- how Part II

This is continued question from P开发者_如何学Pythonar1.

Scenario: I've drop down shown below.

Jquery dependent drop down boxes populate- how Part II

Lets say today is Sat, 07 May 2011 10AM.

Case1: From drop down shown above, if the user selects Fri, 06 May 2011 the hour drop should contain 10-23.

Case2: But, if the user selects Sat, 07 may 2011 then the Start Date Hour Drop down should contain 00-10 ie. midnight to current time.

could anyone guide me if this is possible at all using JQuery please?


Like this:

function addHoursRangeToSelect(select, from, to){
  $(select).empty();
  for(var h=from; h<=to; h++){
      $("<option />").val(h).html(addZero(n)).appendTo($(select));
  }
  function addZero(n){ return (n < 10 ? "0"+n : ""+n); }
}

$("#startDate").change(function(){
   var startHH1, endHH1;
   switch($(this).val()){
      case "2011-05-06":  //Assuming "2011-05-06" is the value of 'Fri, 06 May 2011' option
          startHH1 = 10; endHH1 = 23; break;
      case "2011-05-07": //Assuming "2011-05-06" is the value of 'Sat, 07 may 2011' option
          startHH1 = 0; endHH1 = 10; break;
   }
   addHoursRangeToSelect("#startHH1", startHH1, endHH1);
});

Hope this helps. Cheers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜