title: how to repopulating a dropdown in codeigniter after form validation fails?
body: <pre><code>&lt;select style="width:25%;" name='state' &lt;?php if(form_error('state') != '') {  echo 'id=error'; } ?&gt;&gt;
  &lt;option value=''&gt;State&lt;/option&gt;
   &lt;?php  foreach($states-&gt;result() as $row)
   {
   echo "&lt;option value='$row-&gt;state_name'&gt;". $row-&gt;state_name."&lt;/option&gt;";
   }  ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>hi, i am facing problem in the above code, please help me,
  set_value is not working for me, dropdown is not populating after form validation fails , thanks in advance
   or </p>
  
  <p>does something like this works, here target is hidden value. now how to set target value to drop down value(option value)</p>
  
  <pre><code>  &lt;script&gt;
      window.onload = function (){
      target=document.getElementById('target').value;
          if(target.length!=''){
     // document.getElementByName('state').value=target;
          }
      }
      &lt;/script&gt;
  </code></pre>