Skip to content

Instantly share code, notes, and snippets.

@janv
Created January 18, 2011 21:49
Show Gist options
  • Save janv/785225 to your computer and use it in GitHub Desktop.
Save janv/785225 to your computer and use it in GitHub Desktop.
function time_select(time_str) {
time_str = time_str.match(/(\d+):(\d+)/)
if(time_str) {
var h = time_str[1]
var m = time_str[2]
}
var buf = '<select class="time_h">'
for (var i=0; i < 24; i++) {
var is = i < 10 ? "0"+i : i;
buf += '<option' + (i == h ? ' selected' : '' ) + '>' + is + '</option>'
};
buf += '</select>:<select class="time_m">'
for (var i=0; i < 60; i++) {
var is = i < 10 ? "0"+i : i;
buf += '<option' + (i == m ? ' selected' : '' ) + '>' + is + '</option>'
};
buf += '</select>'
return buf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment