javascript - Why is this code not properly displaying the output? -


this question has answer here:

i'm having fun screwing around, , built this. should taking values forms, putting them through !a != !b mockup logical xor, , outputting <p> tag, i'm not sure why it's not working. me it?

window.onload = function(){   function xor() {      var = document.getelementbyid("aform");      var b = document.getelementbyid("bform");      var output = (!a != !b);      document.getelementbyid("xoroutput").innerhtml = "output value: " + output;   }  };
<h2>random testing</h2>      <h3>logical xor test</h3>          <h4>first input value</h4>              <form id="aform">                  <input type="radio" name="avalue" value="true">true                  <br>                  <input type="radio" name="avalue" value="false">false              </form>          <h4>second input value</h4>              <form id="bform">                  <input type="radio" name="bvalue" value="true">true                  <br>                  <input type="radio" name="bvalue" value="false">false              </form>          <br>          <button onclick="xor()">perform xor</button>          <p id="xoroutput"></p>

the problem rather simple. jsfiddle implicitly wrap inserted javascript inside of window.onload. in other words, code looks this:

window.onload = function(){  //insert code here }; 

if create function in there, scoped anonymous function , not accessible globally when attempt attach event handler inline.

changing fiddle "no wrap, in head" option fix problem.

enter image description here

https://jsfiddle.net/o3xw7ghh/11/


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -