# Disable double-click with link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097>\
**Category:** Rails\
**Created:** [February 23, 2009, 11:47am UTC](https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097 "2009-02-23T11:47:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 23, 2009, 11:47am UTC](https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097/1 "2009-02-23T11:47:32Z")

</div>

I’m using link\_to\_remote to load and show a number of partials and am  
looking for a way to prevent multiple clicks on the link. I tried  
searching around, but couldn’t really find anything. The way it is  
set up now is that if a user double clicks fast enough, two ajax  
requests are sent to the server and when both are loaded, things get  
messed up. I’m looking for a good way to eliminate the possibility of  
that second ajax request. Is that possible using link\_to\_remote?  
This is one of my link\_to\_remotes:

```
<%= link_to_remote "Show", :url => {:action => "show"} %>
```

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 23, 2009, 12:14pm UTC](https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097/2 "2009-02-23T12:14:05Z")

</div>

On 23 Feb 2009, at 10:46, David wrote:

> \<%= link\_to\_remote “Show”, :url =\> {:action =\> “show”} %\>  
> You could use :before / :onComplete callbacks to disable stuff (either  
> by setting some js variable or just disabling the link)

Fred

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 25, 2009, 4:28am UTC](https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097/3 "2009-02-25T04:28:27Z")

</div>

Heres what I have and it seems to work:

```
$('popup_link_<%= @day %>').observe('click', function()

```

{  
if(!making\_ajax\_request) {  
making\_ajax\_request = true;  
new Ajax.Request( ‘/users/serve\_popup’, { parameters: { day: \<  
%= @day %\>},  
onComplete: function(){ making\_ajax\_request =  
false;},  
} );  
} else { }

```
  })

```

Does anyone have any suggestions or see anything wrong? I am  
wondering if it would be better to use onSuccess rather than  
onComplete, but maybe not, b/c then if an ajax.request was  
unsuccessful the making\_ajax\_request would be left as true and the  
user would be unable to make another ajax request.

On Feb 23, 3:12 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 25, 2009, 9:00am UTC](https://www.ruby-forum.com/t/disable-double-click-with-link-to-remote/161097/4 "2009-02-25T09:00:50Z")

</div>

I had a similar problem recently, and was able to effectively disable  
the link (and prevent multiple clicks) by using the :before directive:

:before=\>“this.style.display=‘none’”

Note: this was only tested in Safari and Firefox…
