tags:

views:

50

answers:

3

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>
+2  A: 

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);
Chris Pebble
The question asked for a way to disable/enable a button by name not by id.
davgothic
this code does not work, see my updated html code above!
Tom
Ah! Thanks for the comment, updated.
Chris Pebble
+2  A: 

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.

davgothic
thanks but this code does not work, see my updated html code above!
Tom
Try my revised answer :)
davgothic
A: 

At least one answer has already been given which should work.

What I'd say though is that you'd be well advised to always have an ID on your elements, and not just rely on the name attribute. The name attribute is really only intended as a marker for posting form items.

CSS and the Javascript DOM are both optimised to look at IDs. You can do it by name, as in the answers you've already been given, but it's much less efficient - even if you can do it in the same amount of code, the browser will have to do more work behind the scenes.

Also some of the techniques for accessing elements by name are not available in all browsers (older versions of IE in particular have issues with [attribute] classes in CSS).

Spudley