Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable/enable a button by jquery

Tags:

jquery

how to disable/enable a specific button by jquery ( by name )?

The button does not have ID , just this code:

<button onclick="$('ChangeAction').value='SaveAndDoOrder';" value="Bye" name="SaveAndDoOrder" type="submit">
        <i class="Icon ContinueIconTiny"></i>
        <span class="SelectedItem">Bye</span>
      </button>
like image 413
Tom Avatar asked Sep 24 '10 10:09

Tom


2 Answers

I would recommend using ID instead of name, like:

$("#myButton").attr("disabled", true);

This will add the disabled attribute to the button which your browser will then automaticallly disable. If you want to use name you can use it like this:

$("button[name=myButton]").attr("disabled", true);
like image 97
Chris Van Opstal Avatar answered Nov 09 '22 00:11

Chris Van Opstal


Try this:

$("button[name=SaveAndDoOrder]").attr("disabled", "disabled");

That will disable a button with a name attribute equal to nameOfButton.

$("button[name=SaveAndDoOrder]").removeAttr("disabled");

That will remove the disable attribute from the same button.

like image 24
David Hancock Avatar answered Nov 09 '22 00:11

David Hancock