Don’t let your link that have a critical action (such as delete some data or something else) fly away on their own self, we must put a confirmation before do the action to prevent user’s mistake. Now, let us make that one.
Java Script has a built-in function to create a user confirmation box ( confirm() ), it means we can call that confirmation box to confirm user’s action. So if the user click a link, they must confirm that before we process the action. If the answer is cancel the default action will be cancelled and vice versa. We can use preventDefault() function to cancel the default action from our link. Take a look at following script. (Implementation #1).
$('.ask-plain').click(function(e) { e.preventDefault(); thisHref = $(this).attr('href'); if(confirm('Are you sure')) { window.location = thisHref; } });
If the user click the link we cancel its default action, grab its default link and confirm the user. If the user confirms his action then we’ll redirect to the default link. But that’s too plain, we’ll replace them with a cute one by adding some CSS properties and jQuery magic. (Implementation #2 and #3).
$('.ask').click(function(e) { e.preventDefault(); thisHref = $(this).attr('href'); if($(this).next('div.question').length <= 0) $(this).after('<div class="question">Are you sure?<br/> <span class="yes">Yes</span><span class="cancel">Cancel</span></div>'); $('.question').animate({opacity: 1}, 300); $('.yes').live('click', function(){ window.location = thisHref; }); $('.cancel').live('click', function(){ $(this).parents('div.question').fadeOut(300, function() { $(this).remove(); }); });
The process is similar to the first script, but we’ll use our customized confirmation box (div with class question) instead of confirm() function. By attaching div element after clicked link element, our confirmation box will appear and displaying a confirmation. If the user confirms his action then we’ll redirect to the default link, else we’ll remove our confirmation box. That’s it, we have a cute confirmation box
[CodeSnippet] jQuery : Confirm User’s Action (via @hdytsgt)
[Community News] jQuery Fundamentals
RGraph : HTML5 Canvas Graph Library
jQuery Plugin : jQuery iPhone UI
Pikachoose : Another jQuery Plugin for Image Gallery
HTML5 Security Cheatsheet
[Community News] How to turn any jQuery plugin into a Wordpress one
Zoom Your Element Using Zoomooz.js
[Community News] Build a Flash-like Game With Scripty2
[Community News] CSS3 Transitions available on Firefox 3.7
[Community News] CSS from the Ground Up
- How To Create iPhone-Style Navigation (Part I)
This post has got 23 shouts so far - jQuery Plugin : jConfirmAction
This post has got 34 shouts so far - iPhone-Style Navigation:AJAX + Rotate (Part II)
This post has got 12 shouts so far - Simple Flip Puzzle Effect with jQuery
This post has got 6 shouts so far - Howto Create Mac-like Login Form
This post has got 7 shouts so far - Implement Password Strength Meter & Gauge.js
This post has got 8 shouts so far - Stylize Your Own Checkboxes
This post has got 15 shouts so far - Create Animated Navigation Menu From Stratch
This post has got 7 shouts so far
- Looks nice
by TheShadow on Filter Image View Using jQuery - Nice drop down menu tutorial.
by TheShadow on Simple CSS3 Dropdown Menu - love your site
by eJobsViet on Free Web UI Element Pack - @Andrew Ellis & @Hidayat Sagita take a look at this little test...
by Pomeh on jQuery Plugin : jConfirmAction - Hi, noob question, how do I use WebUI in WordPress and how do I use these...
by martin on Free Web UI Element Pack




[...] [CodeSnippet] jQuery : Confirm User’s Action [...]
[User Link:[CodeSnippet] jQuery : Confirm User’s Action] | Tips for Designers and Developers | tripwire magazine
CSS Brigit | [CodeSnippet] jQuery : Confirm User’s Action
[CodeSnippet] jQuery : Confirm User’s Action…
Dont let your link that have a critical action (such as delete some data or something else) fly away on their own self, we must put a confirmation before do the action to prevent users mistake….
Bogdan Pop
Confirmation popup messages are the worst thing to do!
Try reading http://www.webia.info/articles/usability/buttons-and-usability/ series to see how’s the best way to go for this.