jquery - Select end_time which is greater than start_time -


i'm using jquery in rails app show start time , end time, come helper (i'm not using datepicker).

in form:

 .field      = f.label :start_time      = f.select :start_time, options_for_select( [""] + start_time, "#{f.object.start_time.strip}")            .span#end_time       .field         = f.label :end_time         = f.select :end_time, options_for_select( [""] + end_time, "#{f.object.end_time.strip}") 

the time list comes helper (i.e. start_time , end_time). how can validate time can select end_time greater start_time?

you can disable options http://www.w3schools.com/tags/att_option_disabled.asp.

i'd use javascript run through array of "end_time" select options , disable less "start_time".

something (id's , stuff need modified):

$("#start_time").change(function() {     // start time     var start_time = $("#start_time").find(":selected").text();      // iterate through end time options     $("#end_time option").each(function() {         var end_time = $(this).text();         // depending on how end_time , start_time formatted may need conversion here         if (start_time > end_time) {             $(this).attr('disabled','disabled');         }     }); )}; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -