How do I pass values from a ruby back-end to a jquery confirmation dialog? -
i'm building web application ruby back-end (mostly sinatra, not rails). application manage institutions, people , subscriptions.
i wanted have custom confirmation dialog boxes when user deletes something. example:
if user deletes institution named "company a", want say: are sure want delete company a
if delete person named "john doe", want say: are sure want delete john doe?
if delete subscription, called "subscription a", john doe, want say: are sure want delete subscription john doe
i have jquery-based delete confirmation dialog looks this:
$('a.delete-action').click(function(event) { if (confirm("are sure want delete this?")) { return true; } return false; });
the associated html , erb are:
<p><a class="action-link delete-action" href="/institutions/<%= @institution.id %>/remove">remove <%= @institution.name %></a></p>
how pass in name of institution/person/subscription/all of things jquery dialog?
thanks in advance!
put name attribute on link
<a href='...' data-name='john doe'>...</a>
then extract attribute in click handler
$('a.delete-action').click(function(event) { var name = $(this).data('name') var prompt = "are sure want delete " + name + "?" if (confirm(prompt)) { return true; } return false; });
Comments
Post a Comment