开发者

Javascript - Disable a control when a drop down list selected index changed

开发者 https://www.devze.com 2023-01-06 22:19 出处:网络
I need to know how to disable a button when the selected index of a drop down list has changed. I want to do it in ja开发者_如何学运维vascript because i don\'t want to cause a postback.

I need to know how to disable a button when the selected index of a drop down list has changed. I want to do it in ja开发者_如何学运维vascript because i don't want to cause a postback.

Thanks.


Add this JavaScript function (it assumes your button has a my-button id):

function disableButton()
{
  button = document.getElementById("my-button");
  button.disabled = true;
}

In order to respond of the change of the selected index, add this onchange event to the dropdown: onchange="disableButton()"

Edit: For more information about the disabled property go to w3schools, they have lots of information about JavaScript and the HTML DOM.

0

精彩评论

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