I have a few items in a list, each item has a delete link, I want a reveal modal box shown when they press the delete button with a YES and Cancel link inside.
If the user presses the YES button the reveal modal should redirect to something like this:
www.url.com/delete/item_id
how could I pass the item_id to the Reveal modal box?
Foundation reveal modal box: http://foundation.zurb.com/docs/reveal.php
Modal Box (item_id should be passed to modal box):
<div id="myModal" class="reveal-modal [expand, xlarge, large, medium, small]">
<h2>Are you sure you want to delete this item?</h2>
<a href="/delete/item_id">Yes</a>
<a class="close-reveal-modal">Cancel</a>
</div>
Calling Reveal:
<script type="text/javascript">
$(document).ready(function() {
$("#deleteItem").click(function() {
$("#myModal").reveal();
});
});
</script>
HTML (item_id should be passed to modal):
<a href="item_id" class="button" data-reveal-id="myModal" id="deleteItem">Delete Item</a>
Set the value using jQuery before the .reveal();
is called
UPDATED: See jsFiddle: http://jsfiddle.net/jgprU/
Html:
<ul id="deleteItem">
<li><a href="10">Click Me</a></li>
<li><a href="20">Click Me</a></li>
<li><a href="30">Click Me</a></li>
</ul>
<div id="myModal" class="reveal-modal">
<h2>Are you sure you want to delete <span id="targetName">error</span>?</h2>
<a id="confirmDelete" href="setMe">Yes</a>
<a class="close-reveal-modal">Cancel</a>
</div>
Javascript:
$(document).ready(function() {
$("#deleteItem a").click(function(e) {
e.preventDefault();
var target = $(this).attr('href');
$("#confirmDelete").attr('href','/delete/' + target)
$("#targetName").text(target);
$("#myModal").reveal();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With