# Link\_to\_remote :confirm =\> as JavaScript function (dynamic)

**URL:** <https://www.ruby-forum.com/t/link-to-remote-confirm-as-javascript-function-dynamic/151548>\
**Category:** Rails\
**Created:** [October 22, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/link-to-remote-confirm-as-javascript-function-dynamic/151548 "2008-10-22T19:17:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [October 22, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/link-to-remote-confirm-as-javascript-function-dynamic/151548/1 "2008-10-22T19:17:07Z")

</div>

Hey all,

Normally you can use the :confirm functionality of link\_to\_remote to  
specify the text of a confirmation dialogue.

For example, :confirm =\> “hello” generate:  
\<a href="#" onclick="if (confirm(‘hello’)) { new Ajax.Request …

I’d like to replace “hello” with a JavaScript call (so that the  
confirmation dialogue can contain text based on what a user has so far  
done on the page. If I try to pre-emptively close the quote, it ends up  
just getting escaped, and the function name is simply displayed:

:confirm =\> “’+myFunction()”  
\<a href="#" onclick="if (confirm(’’+myFunction()’)) { new Ajax.Request  
…

Any idea how I might accomplish a dynamic confirmation dialogue?

Thanks!!  
-Jason

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [November 19, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/link-to-remote-confirm-as-javascript-function-dynamic/151548/2 "2008-11-19T18:33:53Z")

</div>

Have you tried :before instead of :confirm  
You’ll have to do your own confirm dialog but your function can  
build the confirm string any way you want

On Oct 22, 11:17 am, Jason C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
