{"id":821,"date":"2014-10-28T08:35:46","date_gmt":"2014-10-28T08:35:46","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=821"},"modified":"2015-08-17T06:13:10","modified_gmt":"2015-08-17T06:13:10","slug":"is-there-an-event-just-before-the-radio-button-is-about-the-be-checked","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/is-there-an-event-just-before-the-radio-button-is-about-the-be-checked\/","title":{"rendered":"Is there an event just before the radio button is about the be checked?"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[821]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/12159212\/is-there-an-event-just-before-the-radio-button-is-about-the-be-checked\">quesiton<\/a> was:<\/p>\n<p style=\"color: #000000;\">This is the part of the code for one of the radio buttons:<\/p>\n<pre class=\"lang:default decode:true \">$(\"#new\").click(function(){\r\n    if( $('#new').is(':checked') )\r\n        $.jGrowl(\"You already have this option selected!\", life: 1500});\r\n    else\r\n        changeOption(1);\r\n});<\/pre>\n<p>Now, I understand that the\u00a0<code>else<\/code>\u00a0part will never run, because the radio button will be already checked on click event. What I&#8217;m wondering is, is there an event which would let me capture the state of the radio button (which is about to be clicked) and therefor determine if he is not yet clicked, and if so change the option to this newly selected one.<\/p>\n<p style=\"color: #000000;\"><span style=\"line-height: 1.5;\">The answer, by <a style=\"color: #4a6b82;\" href=\"http:\/\/stackoverflow.com\/users\/1171873\/joplomacedo\">JOPLOmacedo<\/a>,\u00a0was:<\/span><\/p>\n<blockquote><p>Use the mouseup event instead.<\/p>\n<pre class=\"default prettyprint prettyprinted\"><code><span class=\"pln\">$<\/span><span class=\"pun\">(<\/span><span class=\"str\" style=\"color: #800000;\">\"#new\"<\/span><span class=\"pun\">).<\/span><span class=\"pln\">mouseup<\/span><span class=\"pun\">(<\/span><span class=\"kwd\" style=\"color: #00008b;\">function<\/span><span class=\"pun\">(){<\/span><span class=\"kwd\" style=\"color: #00008b;\">if<\/span><span class=\"pun\">(<\/span><span class=\"pln\"> $<\/span><span class=\"pun\">(<\/span><span class=\"str\" style=\"color: #800000;\">'#new'<\/span><span class=\"pun\">).<\/span><span class=\"kwd\" style=\"color: #00008b;\">is<\/span><span class=\"pun\">(<\/span><span class=\"str\" style=\"color: #800000;\">':checked'<\/span><span class=\"pun\">)<\/span><span class=\"pun\">)<\/span><span class=\"pln\">\r\n        $<\/span><span class=\"pun\">.<\/span><span class=\"pln\">jGrowl<\/span><span class=\"pun\">(<\/span><span class=\"str\" style=\"color: #800000;\">\"You already have this option selected!\"<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> life<\/span><span class=\"pun\">:<\/span><span class=\"lit\" style=\"color: #800000;\">1500<\/span><span class=\"pun\">});<\/span><span class=\"kwd\" style=\"color: #00008b;\">else<\/span><span class=\"pln\">\r\n        changeOption<\/span><span class=\"pun\">(<\/span><span class=\"lit\" style=\"color: #800000;\">1<\/span><span class=\"pun\">);<\/span><span class=\"pun\">});<\/span><\/code><\/pre>\n<p>The\u00a0<a style=\"color: #4a6b82;\" href=\"http:\/\/jsfiddle.net\/joplomacedo\/SCF5K\/\" rel=\"nofollow\">fiddle.<\/a><\/p>\n<p><strong>Edit<\/strong><br \/>\nEven though the mouseup event works, it seems more logical to use the mousedown event.\u00a0<a style=\"color: #4a6b82;\" href=\"http:\/\/jsfiddle.net\/joplomacedo\/SCF5K\/3\/\" rel=\"nofollow\">Here&#8217;s that fiddle<\/a>.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=821"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/821\/revisions"}],"predecessor-version":[{"id":1705,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/821\/revisions\/1705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}