开发者

Disable one Selection Box based on a Selection in another

开发者 https://www.devze.com 2023-01-10 23:57 出处:网络
I have two selection boxes in the same form. I would lik开发者_开发问答e to have one disabled based on some of the options that can be selected in the other selection box. I\'m looking for a solution

I have two selection boxes in the same form. I would lik开发者_开发问答e to have one disabled based on some of the options that can be selected in the other selection box. I'm looking for a solution in JavaScript if possible.


You can use jQuery and do something like this

$('#select1').change(function() {
    if(...) {
        $('#select2').attr('disabled', 'disabled');
    }
});

more info here http://jquery.com/


And if you dont use jquery you can do it like this

<input type="checkbox" id="select1" onchange="disable()">

function disable() {
    if(...) {
        document.getElementById('select2').disabled='disabled';
    }
}
0

精彩评论

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