title: How to call Javascript function inside WTForms radio element?
body: <p>I'm new to wtforms and flask. I'm trying to do so that when that a user changes the radio buttons, the text would change. However, currently the onchange does not work, nor does onclick and when I remove it, the text appears but does not change at all when the buttons are changed and remains the same.
  </p>
  <pre><code>    {{ wtf.form_field(form.doc, class=&quot;form-control&quot;, onchange=&quot;myFunction()&quot;) }}
  
  
      &lt;/div&gt;
     &lt;p id=&quot;demo&quot;&gt;&lt;/p&gt;
  
  &lt;script&gt;
    
    function myFunction(){
           
           if (document.getElementById('doc-0').checked) {
                value = document.getElementById('doc-0').value;
                document.getElementById(&quot;demo&quot;).innerHTML = &quot;You selected: &quot; + value;
            }
  
  
         else if ( document.getElementById('doc-1').checked) {
                rate_value = document.getElementById('doc-1').value;
                document.getElementById(&quot;demo&quot;).innerHTML = &quot;You selected: &quot; + value;
  
          }
          else if (document.getElementById('doc-2').checked) {
                rate_value = document.getElementById('doc-2').value;
                document.getElementById(&quot;demo&quot;).innerHTML = &quot;You selected:&quot; + value;
  
          }
  
          else {
     
            document.getElementById(&quot;demo&quot;).innerHTML = &quot;You selected: NOTHING&quot; ;
          }
       }
  
  
          &lt;/script&gt;
  </code></pre>
  <p>Could someone point out what I'm doing wrong and what I should do. Thank you so much for the help!</p>