title: CodeIgniter - PHP Set_Radio on Radio Input
body: <p>I am working on a website, and I have run into a problem. In order to pre-set or re-input slected values, Codeigniter allows you to use set_radio to solve your problem, seen here:</p>
  
  <pre><code>&lt;td&gt;Do You Have a PayPal Account &lt;span class="error"&gt;*&lt;/span&gt; : &lt;/td&gt;
  &lt;td colspan="2" align="left" valign="top"&gt;&lt;label&gt;   
    &lt;!-- used for validation --&gt;
      &lt;input type="hidden" id="temp_mid" value="" /&gt;
      &lt;input name="mail_account" type="radio" id="p_same" value="same" onclick="dohide_show(this.value);" &lt;?php echo set_radio('mail_account', 'same'); ?&gt;/&gt; Yes(same as email address as above.)&lt;br/&gt;
      &lt;input name="mail_account" type="radio" id="p_diff" value="diff" onclick="dohide_show(this.value);" &lt;?php echo set_radio('mail_account', 'diff'); ?&gt;/&gt; Yes(different than above.)&lt;br/&gt;
      &lt;input name="mail_account" type="radio" id="p_checkInMail" value="checkInMail" onclick="dohide_show(this.value);" &lt;?php echo set_radio('mail_account', 'checkInMail'); ?&gt;/&gt; No(I would prefer to receive a check in the mail.)                  
       &lt;?php echo form_error('mail_account'); ?&gt;           
  
   &lt;/td&gt;
  </code></pre>
  
  <p>This works perfectly fine after validation, as the previous radio button has been selected if there is an error in another part of the form. BUT, when trying to resubmit the page after the user has corrected the error, valditation fails on the radio selection, asking me to click on the radio buttons again, even if the radio button is visually selected on the option I chose before. So I have to choose the radio button again before I can resubmit the form. The alert called is seen here:</p>
  
  <pre><code>function validate_playpal()
          {   
              var temp=$('#temp_mid').val();
              if(temp=="")
              {
                  alert('Please select the PayPal account option.');                  
                  $('#p_same').focus();
                  return false;
              }
              if(document.getElementById('p_diff').checked== true &amp;&amp; document.getElementById('paypal_emailid').value=='')
              {
                  alert('Please provide your PayPal email address.');
                  document.getElementById('paypal_emailid').focus();
                  return false;
              }
  
              if(document.getElementById('paypal_emailid').value!='')
              {
                  if(!email_format(document.getElementById('paypal_emailid').value)){
                      alert('Please enter valid email address.');
                      document.getElementById('paypal_emailid').value="";
                      document.getElementById('paypal_emailid').focus();
                      return false;               
                  }
              }
              return true;
          }
  </code></pre>
  
  <p>Does anyone know why this isn't working, even though it is repopulating the form correctly? Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>For everyone who asked for what Mid_temp does, it appears to me that it just hides the buttons if they do not need to be selected. In the code I have, these are the only places it is mentioned: </p>
  
  <pre><code>    $('#bx').hide();
  if(document.getElementById('p_diff').checked==true){    
      $('#bx').show();
  }
  
  function dohide_show(val){
      if(val=='diff')
      {       
          $('#bx').show();
          $('#paypal_emailid').val('');
          document.getElementById('p_diff').checked=true;
          $('#temp_mid').val('clicked');
      }
      else if(val=='same')
      {       
          $('#bx').hide();
          $('#paypal_emailid').val($('#email_id').val());
          $('#temp_mid').val('clicked');  
      }
      else
      {
          $('#bx').hide();
          $('#paypal_emailid').val($('#email_id').val());
          $('#temp_mid').val('clicked');
      }
  
  }
  </code></pre>
  
  <p>and here, in a completely separate file: </p>
  
  <pre><code>function hide_box()
              {
                  $('#bx').hide();
                  $('#paypal_emailid').val('');
                  $('#temp_mid').val('clicked');
              }
              function show_box()
              {
                  $('#bx').show();
                  $('#paypal_emailid').focus();
                  $('#temp_mid').val('clicked');
              }
  </code></pre>
  
  <p>Also, Paypal Email ID is just checking the paypal email address that the user put in if they have a paypal account. Thanks for the help everyone.</p>