Remove disabled attribute onClick of disabled form field

后端 未结 10 1469
眼角桃花
眼角桃花 2020-12-03 11:28

I have a form field that starts out disabled and has an onClick to enable it. The onClick doesn\'t fire (at least in FF) nor does a simple alert(1);.

The hacky vers

10条回答
  •  长情又很酷
    2020-12-03 12:05

    In order to enable a disabled element on the client side, lets say in response to a checkbox checked or something, I ended up having to use a combination of JS and jQuery, see below:

    //enable the yes & no RB 
    function enable()
    {
            var RBNo = "rbnBusinessType";
            var RBYes = "rbnBusinessType";
    
            //jQuery approach to remove disabled from containing spans            
            $("#" + RBYes).parent().removeAttr('disabled');
            $("#" + RBNo).parent().removeAttr('disabled');
    
            //enable yes and no RBs
            document.getElementById(RBYes).disabled = false;
            document.getElementById(RBNo).disabled = false;               
    
    }
    

    After postback then, you'll need to access the request like the following in order to get at the values of your client side enabled elements:

    this._Organization.BusinessTypeHUbZoneSmall = Request.Params["rbnBusinessTypeHUbZoneSmall"] == rbnBusinessTypeHUbZoneSmallYes.ID;

    Inspiration taken from: https://stackoverflow.com/questions/6995738/asp-javascript-radiobutton-enable-disable-not-included-in-postback-ajax for more information

提交回复
热议问题