title: Validate dynamic radio buttons jQuery
body: <p><strong>Problem:</strong> I can´t validate dynamically created radio buttons.</p>
  
  <p><strong>Question:</strong> how do I use jQuery to validate the radio buttons?</p>
  
  <p>Is it possible to customise the jQuery to validate dynamically created radio buttons? </p>
  
  <p>Any suggestions?</p>
  
  <p><strong>HTML and PHP from my form</strong></p>
  
  <pre><code>&lt;label class="radio"&gt;
      &lt;input type="radio" name='radnummer_varde[&lt;?php echo $kk['radnummer'];?&gt;]' value='1' &lt;?php if (($hamta_formaga['radnummer_varde'] == '1')) echo 'checked="checked" '; ?&gt;&gt;
      &lt;i class="rounded-x"&gt;&lt;/i&gt;Prövas
  &lt;/label&gt;
  
  &lt;label class="radio"&gt;
      &lt;input type="radio" name='radnummer_varde[&lt;?php echo $kk['radnummer'];?&gt;]' value='0' &lt;?php if (($hamta_formaga['radnummer_varde'] == '0')) echo 'checked="checked" '; ?&gt;&gt;
      &lt;i class="rounded-x"&gt;&lt;/i&gt;Prövas ej
  &lt;/label&gt;
  </code></pre>
  
  <p><code>echo $kk['radnummer']</code> is numeric.</p>
  
  <p><strong>Validation via JS</strong></p>
  
  <pre><code>var AbbRedigeraForm = function () {
  
      return {        
  
          initAbbRedigeraForm: function () {
              // Validation
              $("#redigera_abb").validate({
                  // Regler för validation
                  rules:
                  {
                      'radnummer_varde[]':
                      {
                          required: true                      
                      },
                      aktiv:
                      {
                          required: true                      
                      },
                      arbetsomrade:
                      {
                          required: true,
                          minlength: 8,
                          maxlength: 30
                      },
                      syfte:
                      {
                          required: true                      
                      },
                      overgripande_mal:
                      {
                          required: true                      
                      },
                      undervisning:
                      {
                          required: true
                      },
                      redovisningsform:
                      {
                          required: true
                      },
  
                  },
  
                  // Messages for form validation
                  messages:
                  {
                      radnummer_varde:
                      {
                          required: 'Du måste ange detta.'                        
                      },
                      arbetsomrade:
                      {
                          required: 'Skriv en rubrik för arbetsområdet.'
                      },
                      syfte:
                      {
                          required: 'Skriv ett syfte.'                        
                      },
                      overgripande_mal:
                      {
                          required: 'Du måste ange övergripande mål.'
                      },
                      undervisning:
                      {
                          required: 'Du måste skriva något om undervisningen.'
                      },
                      redovisningsform:
                      {
                          required: 'Du måste skriva något om redovisning.'
                      },                  
                  },      
                  // Do not change code below
                  errorPlacement: function(error, element)
                  {
                      error.insertAfter(element.parent());
                  }
              });
          }
  
      };
  
  }();
  </code></pre>
  
  <p><strong>EDIT 2015-03-27:</strong></p>
  
  <p>Option 2</p>
  
  <pre><code>&lt;label class="radio"&gt;
      &lt;input type="radio" name='radnummer_varde[&lt;?php echo $kk['radnummer'];?&gt;]' value='1' &lt;?php if (($hamta_formaga['radnummer_varde'] == '1')) echo 'checked="checked" '; ?&gt;&gt;
      &lt;i class="rounded-x"&gt;&lt;/i&gt;Prövas
  &lt;/label&gt;
  
  &lt;label class="radio"&gt;
      &lt;input type="radio" name='radnummer_varde[&lt;?php echo $kk['radnummer'];?&gt;]' value='0' &lt;?php if (($hamta_formaga['radnummer_varde'] == '0')) echo 'checked="checked" '; ?&gt;&gt;
      &lt;i class="rounded-x"&gt;&lt;/i&gt;Prövas ej
  &lt;/label&gt;
  
  &lt;script type="text/javascript"&gt; 
      $(document).ready(function () {
      $('#redigera_abb').validate({});                                
      $('[name="radnummer_varde[&lt;?php echo $kk['radnummer'];?&gt;]"]').rules('add', {
          required: true,
          messages: {
              required: "At least one option needed."
          }
      }); 
      });                             
  &lt;/script&gt;
  </code></pre>