开发者

How to pass control name in user defined function using jQuery

开发者 https://www.devze.com 2023-01-29 20:58 出处:网络
I have two controls in a form, day of month a开发者_运维知识库nd month. Whenever the user changes the month I want it to change the number of days in the \"day of month\" combo box depending on the mo

I have two controls in a form, day of month a开发者_运维知识库nd month. Whenever the user changes the month I want it to change the number of days in the "day of month" combo box depending on the month. I want to write a user defined function as I have the same logic on many different pages. Does anyone have any ideas about how to do that?


on page load you can do the below

ddl1.attribute.add("onchange", string.Format("functionName('{0}')", ddl2.ClientId););


function daysInMonth(month, year) {
    return new Date(year, month, 0).getDate();
}

function rebuildDaysOfMonthControl(controlId, month)
{
    var currentYear = (new Date).getFullYear();
    var days = daysInMonth(month, currentYear);

    $(controlId).empty();

    //rebuild the days of month control
    for (var x = 1; x <= days; x++) {
        $(controlId).append(
            $('<option></option>').val(x).html(x)
        );
    }
}

$(function () {

    $('#monthControlId').live('change', function () {
        var selectedMonth = $(this).val();

        rebuildDaysOfMonthControl('#daysOfMonthControlId', selectedMonth);

    });

});
0

精彩评论

暂无评论...
验证码 换一张
取 消