开发者

JQuery How to set the value of a hidden field to the selected value of a dropdownlist

开发者 https://www.devze.com 2023-02-16 20:08 出处:网络
I am using MVC 3 and I am trying to take the selected value of a dropdownlist and store it into a hidden field.YearList is my dropdown and DOBYear is the hidden field.The error I am getting is

I am using MVC 3 and I am trying to take the selected value of a dropdownlist and store it into a hidden field. YearList is my dropdown and DOBYear is the hidden field. The error I am getting is

htmlfile: Unexpected call to method or property access.

Anyone have any ideas what might be happening? 开发者_运维问答 Seems like it should be a pretty easy and common thing to do.

$(function () {
    $("#YearList").change(function () {
        $('#DOBYear').html($('#YearList').val()); 
    });
});

Thanks,

Rhonda


You're probably looking for:

$(function () {
    $("#YearList").change(function () {
        $('#DOBYear').val(this.value);
    });
});

(Use .val() to populate the value of the hidden input instead of .html())

0

精彩评论

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