title: How can I cancel a users radiobutton selection, after a confirm dialog cancel selection?
body: <p>In a bigger project, I have a group of radiobuttons, which updates the text in a textarea. Sometimes however, I need to let the user choose if they really want to change the text.</p>
  
  <p>I'm using hidden radiobuttons, and only the labels are showing. I've been able to present the confirm dialog, and prevent the change of text in the textarea, but I have not been able to actually stop the radiobutton from checking the newly clicked element. I've tried to save a reference to the previously checked radiobutton, but I suspect that it is already to late in the code. To further illustrate, I have made a JSFiddle. There should never be a mismatch between button texts and text in the area, once one has been loaded. </p>
  
  <p><a href="http://jsfiddle.net/e0bxnghc/1/" rel="nofollow">http://jsfiddle.net/e0bxnghc/1/</a></p>
  
  <p>So is there a way to cancel the user's selection of the radiobutton?</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;nav id="selectors" class="segmented-button"&gt;
      &lt;input type="radio" name="group-1" value="car" id="radio1"&gt;
      &lt;label for="radio1" class="first"&gt;Car&lt;/label&gt; 
      &lt;input type="radio" name="group-1" value="boat" id="radio2"&gt;
      &lt;label for="radio2"&gt;Boat&lt;/label&gt; 
      &lt;input type="radio" name="group-1" value="plane" id="radio3"&gt;
      &lt;label for="radio3"&gt;Plane&lt;/label&gt; 
      &lt;input type="radio" name="group-1" value="train" id="radio4"&gt;
      &lt;label for="radio4" class="last"&gt;Train&lt;/label&gt; 
  &lt;/nav&gt;
  
      &lt;textarea id="output"&gt;output area&lt;/textarea&gt;
  </code></pre>
  
  <p>javascript:</p>
  
  <pre><code> $(document).ready(function(){
      $('#selectors label').click(function() {    
          var element = $(this).prev();
          var confirmed = false;
          var previousSelected =  $("input[name=group-1]:checked");
          var r = confirm("Are you sure you want to change the text?");
          if (r == true) {
              $("#output").val(element.val());
  
          } else{
              previousSelected.checked = true;
          }
      });
  });
  </code></pre>