user1453851
user1453851

Reputation: 129

using Jquery button unable to disable the button

Iam not able to disable the button using jquery. I tried all the possible options but it is not working. Iam able to access and display the other properties of button, but disabling is not working. Iam using Jquery 1.8 and browser IE 7. Below is the code. Please help me in this regard.

<input type="button" class="actionButton" style="display: inline;" onclick="addCompany();" id="addCompanyId" value="Add country1111">

function setParentCompany(comId) {
    $('#parentCompanyDomain').val(comId);

    /* var buttonObj = $("#addCompanyId");
    //alert("buttonObj"+ buttonObj[0].id);
    buttonObj.setAttribute("disabled",true);
    //alert("button disabled value11122::"+buttonObj[0].attr('disabled')); */
    alert("id::"+$('#addCompanyId').attr("id"));
    alert("class::"+$('#addCompanyId').attr("class"));
    alert("value::"+$('#addCompanyId').attr("value"));
    alert("disable::"+$('#addCompanyId').attr("disabled"));

    $('#addCompanyId').attr("disabled",true);

} 

Upvotes: 1

Views: 123

Answers (5)

HIRA THAKUR
HIRA THAKUR

Reputation: 17757

    $(document).ready(function(){
        $('#addCompanyId').attr("disabled", "disabled");//for jquery <1.6

                           or

        $('#addCompanyId').prop('disabled', true);//for jquery =>1.6
        }

This will work!!!

Upvotes: 1

Code Lღver
Code Lღver

Reputation: 15593

Instead of the below code:

$('#addCompanyId').attr("disabled",true);

Use the below code:

$('#addCompanyId').attr("disabled","disabled");

Reference site.

Upvotes: 0

Rob
Rob

Reputation: 11798

A combination of both of the above will do it:

$('#addCompanyId').prop('disabled','disabled')

Upvotes: 0

Ayyappan Sekar
Ayyappan Sekar

Reputation: 11475

try this...

$('#addCompanyId').prop('disabled', true);

Upvotes: 1

U.P
U.P

Reputation: 7442

Try

$('#addCompanyId').prop("disabled",true)

true / false doesn't work with attr() so you should use prop()

If you have to use attr() then do the following

$('#addCompanyId').attr("disabled","disabled");

Upvotes: 1

Related Questions