JSFiddle - React, Tailwind, and code Playground

by jhegeduis

HTML

<select id="hoursSel"></select>
<select id="minuteSel"></select>

JavaScript

var hourMax = 12;
var minuteMax = 59;


var createOpts = function(num, end, options){
    var t = num < 10 ? '0' + num : num;
    options += '<option value="' + t + '">' + t + '</option>';
    return num == end ? options : createOpts(num+1,end, options);
};

// onload build your hour select dropdown
 $("#hoursSel").append(createOpts(1,hourMax,''));


// attach your change function here
$('#hoursSel').change(function(){
    // remove all options from minute selection first
    $('#minuteSel')
    .find('option')
    .remove();

    // get the value and check if 12.  return if so
    var hour = $('#hoursSel').val();
    if (hour == 12){
        $("#minuteSel").append(createOpts(0,0,''));
        return;
    }
    $("#minuteSel").append(createOpts(0,minuteMax,''));
});