Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I fn hate anonymous functions. While they can have a place, it's mostly just lazy programming, imho.</p> <p>Here's some code that should hopefully be more clear for you to understand.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; window.addEventListener('load', mInit, false); function mInit() { var radioBtns = document.querySelectorAll("input[type=radio]"); var i, n = radioBtns.length; for (i=0; i&lt;n; i++) { var btnGroupName = radioBtns[i].getAttribute('name'); if (btnGroupName == 'yesNo') radioBtns[i].addEventListener('change', onRbGroup1Change, false); else if (btnGroupName == 'gender') radioBtns[i].addEventListener('change', onRbGroup2Change, false); } } function onRbGroup1Change() { document.getElementById('radioResult').innerHTML = "Value of chosen radio button is: " + this.value; } function onRbGroup2Change() { document.getElementById('radioResult2').innerHTML = "Gender of chosen radio button is: " + this.value; } &lt;/script&gt; &lt;style&gt; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;label&gt;Yes&lt;input type="radio" name="yesNo" value="afirmative"/&gt;&lt;/label&gt; &lt;label&gt;No&lt;input type="radio" name="yesNo" value="negative"/&gt;&lt;/label&gt; &lt;div id='radioResult'&gt;You need to select a radio-button first!&lt;/div&gt; &lt;label&gt;Girl&lt;input type="radio" name="gender" value="Female"/&gt;&lt;/label&gt; &lt;label&gt;Boy&lt;input type="radio" name="gender" value="Male"/&gt;&lt;/label&gt; &lt;div id='radioResult2'&gt;You need to select a radio-button first!&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload