# How to disable button generated by submit\_to\_remote?

**URL:** <https://www.ruby-forum.com/t/how-to-disable-button-generated-by-submit-to-remote/193643>\
**Category:** Rails\
**Created:** [August 20, 2010, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-disable-button-generated-by-submit-to-remote/193643 "2010-08-20T23:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 20, 2010, 11:36pm UTC](https://www.ruby-forum.com/t/how-to-disable-button-generated-by-submit-to-remote/193643/1 "2010-08-20T23:36:16Z")

</div>

I got a submit\_to\_remote button that I’d like to show as disabled on a  
certain condition. I’d assume the usual :disabled =\> true would do but I  
have not been able to. Comparing page source shows that for example:

\<%= submit\_to\_remote “add”, “Add”, :url =\> { :action =\> “add\_groups” },  
:update =\> ‘divgrouptable’, :disabled =\> true %\>

the “:disabled = true” statement has no effect on the generated html.  
Also tried “{ :disabled =\> true }” and a few others.

I went as far as writing on-load hook and disabling the buttons in the  
java script as shown below but sounds like a lot of effort to achieve  
this. How could I make this less “obtrusive”?

function disable\_buttons()  
{  
\<% if @readonly %\>  
document.getElementsByName(‘add’)[0].disabled = 1  
document.getElementsByName(‘remove’)[0].disabled = 1  
\<% end %\>  
}

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 22, 2010, 8:43pm UTC](https://www.ruby-forum.com/t/how-to-disable-button-generated-by-submit-to-remote/193643/2 "2010-08-22T20:43:35Z")

</div>

These 2 versions will disable the button:

\<%= submit\_to\_remote “add”, “Add”, :url =\> { :action =\>  
“add\_groups” }, :html =\> {:update =\> ‘divgrouptable’, :disabled =\>  
true} %\>  
\<%= submit\_to\_remote “add”, “Add”, :url =\> { :action =\>  
“add\_groups” }, :update =\> ‘divgrouptable’, :html =\> {:disabled =\>  
true} %\>

I have never used the submit\_to\_remote before and I’m not too familiar  
with the Ajax helpers so I’m not sure if :update has to be inside  
the :html hash or not. In any case, in the docs the example reads like  
this:

:update =\> { :success =\> “succeed”, :failure =\> “fail” }

I don’t know if your :update stuff will work as it is.

---

<div class="post-metadata">

**Author:** ![techy\_bolek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee59a6/32.png) [@techy\_bolek](https://www.ruby-forum.com/u/techy_bolek)\
**Post date:** [August 26, 2010, 3:38pm UTC](https://www.ruby-forum.com/t/how-to-disable-button-generated-by-submit-to-remote/193643/3 "2010-08-26T15:38:16Z")

</div>

Both examples work, thanks.
