title: How do I get this simple Try/Catch test to work?
body: <p>A user selects whether or not to run an alert line of code with an error using a radio button. The idea is the user selects a radio element, a function(setError()) is run that locates the selected radio button and then passes the value to another function (runCode()) that uses IF statements to decide whether or not to include errors in the alert. If the user chooses to alert with an error then a Try Catch code should capture the error and display the error in the <p> element already in the HTML.</p>
  
  <pre><code>&lt;form name="Form"&gt;
         Run Code:
      &lt;input type="radio" name="errorRad" onchange="setError()" value="yes"&gt;With Error
      &lt;input type="radio" name="errorRad" onchange="setError()" value="no"&gt;Without Error
      &lt;/form&gt;
          &lt;p id="t"&gt;
          &lt;/p&gt;
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>&lt;script&gt;
  
  
  function setError() {
      var x;
   var rad = document.forms["Form"]["errorRad"];
      for (i = 0; i &lt; rad.length; i++) {
      if (rad[i].checked){
      x = rad[i].value;
      }
      }
     runCode(x);
  
      }
         function runCode(error) {
     if (error == "yes") {
      try {
      allert(a successful alert box);
      } catch(err) {
      document.getElementById("t").innerHTML = err.message;
      }
      }else if (error == "no") {
      alert("a successful alert box");
      }
  
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Interestingly, after testing this by placing random alert boxes in during the code to test where the code gets up to before breaking: the code doesn't even seem to call the first function (setError). The onchange event doesn't seem to work properly. Perhaps by syntax is wrong or an alternative event is better. Another point of interest is the calling of the second function (runCode). I'm not too good at passing parameters in JavaScript (I'm not good at much tbh) and I'm not sure if my method will work.</p>
  
  <p>JS Fiddle: <a href="http://jsfiddle.net/rwowf5j8/22/" rel="nofollow">http://jsfiddle.net/rwowf5j8/22/</a></p>