Software Archive
Read-only legacy content
17061 Discussions

Cannot Disable/Enable a button

Nick_F_2
New Contributor III
503 Views

Hi

I have this Javascript:

function salesType(){

    var saleschecked = $('#salesType').prop("checked");
    localStorage.setItem("salesType",true);
    if (saleschecked == true) {
   $("#atbutton").removeAttr("disabled");
        $('#sales').prop('readonly', true);
    }
    else
        {
    $("#atbutton").attr("disabled", "disabled");
    $('#sales').prop('readonly', false);
        }
}

and this HTML

<div class="ui-checkbox widget uib_w_65 CheckboxMargin CheckboxWidth" data-uib="jquery_mobile/checkbox" data-ver="0">
                        <label>Input Sales
                            <input type="checkbox" onclick="javascript:salesType()" name="salesType" id="salesType" data-mini="true">
                        </label>
                    </div>
                    <div class="table-thing with-label widget uib_w_66 d-margins UpperWidths LabelText InputText" data-uib="jquery_mobile/input" data-ver="0">
                        <label class="narrow-control label-inline" for="sales">Sales</label>
                        <input class="wide-control" type="number" data-mini="true" value="0" name="sales" id="sales">
                    </div>
                    <a class="widget uib_w_67 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" id="atbutton" name="atbutton" disabled="disabled">Advanced Data</a>

On page load the Advanced Data button should be disabled and when I check the checkbox, the Sales input becomes readonly as required, but the Advanced Data button is always enabled, I cannot swap between disabled and enabled on checkbox click.

Any thoughts please.

0 Kudos
1 Solution
Diego_Calp
Valued Contributor I
505 Views

OK.

XDK creates JQM buttons as link buttons. They don't have methods as enable disable associated.

http://demos.jquerymobile.com/1.2.0/docs/buttons/buttons-methods.html

 

Link buttons (<a> element) doesn't have a disabled property. You need to use a workaround like this:

http://stackoverflow.com/questions/6438659/how-to-disable-a-link-button-in-jquery-mobile

Regards,

Diego

View solution in original post

0 Kudos
9 Replies
Hamilton_Tenório_da_
Valued Contributor I
505 Views

Try 

$('#atbutton').prop('checked', false);

 

0 Kudos
Nick_F_2
New Contributor III
505 Views

Hi Thanks for your help, but that doesn't work.

Also I am trying to disable a button not check/uncheck a checkbox.
 

0 Kudos
Nick_F_2
New Contributor III
505 Views

Bump

0 Kudos
Diego_Calp
Valued Contributor I
505 Views

Hi,

With AF3 this work for me:

$("#atbutton").prop("disabled",true);

Regards

Diego

0 Kudos
Nick_F_2
New Contributor III
505 Views

Nope tried that before and tried it again, but the button refuses to change state.

0 Kudos
Diego_Calp
Valued Contributor I
505 Views

Strange, I just tried it again. The button remains unchanged, but not respond to clicks. If I change with the same method to disabled = false, it is working again.

Are you using App Framework 3 or other?

0 Kudos
Nick_F_2
New Contributor III
505 Views

I'm using jQuery Mobile. Its an app I've been working on for a while.

0 Kudos
Diego_Calp
Valued Contributor I
506 Views

OK.

XDK creates JQM buttons as link buttons. They don't have methods as enable disable associated.

http://demos.jquerymobile.com/1.2.0/docs/buttons/buttons-methods.html

 

Link buttons (<a> element) doesn't have a disabled property. You need to use a workaround like this:

http://stackoverflow.com/questions/6438659/how-to-disable-a-link-button-in-jquery-mobile

Regards,

Diego

0 Kudos
Nick_F_2
New Contributor III
505 Views

Thats a very good point, hadn't considered that.

I will take a look at the links you have posted. Many thanks.

0 Kudos
Reply