1

This is continued question from Par1.

Scenario: I've drop down shown below.

enter image description here

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?

Community
  • 1
  • 1
Nil Pun
  • 17,035
  • 39
  • 172
  • 294

1 Answers1

1

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

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61
  • Thanks @Edgar. I think I must not have explained clearly. We need to populate only Start Hour Drop down (#startHH2 on your solution) from 10,11.....23 for case 1 and 0,1,2...10 for case2. I've updated the image on question so that it only shows 1 drop down. – Nil Pun May 07 '11 at 00:33
  • @flybyte: Ohh, i understand now. I'm updating my solution to fullfill this requirement. – Edgar Villegas Alvarado May 07 '11 at 02:47