I am trying to write a generic JavaScript subroutine to set the periodicity in the week:var items = {0: none, 1:Daily, 2: Every weekday (Monday to Friday), 3: Weekly};I would like to improve this to make it more generic and readable if possible.var callback = selectDay(idValue);createSelect(items, idValue, callback);var createSelect = function (items, idValue) {    var selElem = document.createElement(select);    $.each(items, function (key, value) {        var ov = document.createElement(option);        ov.value = key;        ov.appendChild(document.createTextNode(value));        selElem.appendChild(ov);    });    $(idValue).prepend(selElem);};var selectDay = function (idValue, element) {    var element = $(idValue);    var childElements = idValue + '_';    element.find('select').change(function () {        if($(this).val() === '0') {            element.find('label').hide();            $(this).closest('div').find('input').attr(checked, false);        }        if($(this).val() === '1') {            element.find('label').hide();            $(this).closest('div').find('input').attr(checked, true);        }        if($(this).val() === '2') {            element.find('label').show();            for (var i = 0; i < 5; i += 1) {                $(childElements + i).attr(checked, true);            }            for (var i = 5; i < 7; i += 1) {                $(childElements + i).attr(checked, false);            }        }        if($(this).val() === '3') {            element.find('label').show();            $(this).closest('div').find('input').attr(checked, false);            $(childElements + (new Date()).getDay()).attr(checked, true);        }    });};var items = {0: none, 1:Daily, 2: Every weekday (Monday to Friday), 3: Weekly};var idValue = '#contest_data_updatePeriodicity_days';createSelect(items, idValue);selectDay(idValue);My questions are:How can I ameliorate this piece of code?    How can make a callback in order to make something like this?JSFiddle
Setting periodicity in the week in Google Calendar
javascript;jquery;datetime