开发者

where to add- class="required" (jquery validation) in form_dropdown?

开发者 https://www.devze.com 2023-04-11 04:59 出处:网络
I have a dropdown list which is being populated from database. It is working fine but in the form_dropdown in the view file, I want to add class=\"required\" for validating the dropdown using Jquery.

I have a dropdown list which is being populated from database. It is working fine but in the form_dropdown in the view file, I want to add class="required" for validating the dropdown using Jquery. I have tried to make it work but as it turned out it won't work. Would you please kindly help me where exactly to put the class="required" - and make the jquery validation work?

Thanks in Advance

I have this in my controller

// To get the batch name
$this->load->model('dropdown_batchlist');
$data['dropdown_batchlist']= $this->dropdown_batchlist->dropdown_batchlist();

this in my model-

function dropdown_batchlist() {
  $this->db->select('batchname, batchid');
  $records=$this->db->get('batch');

      $data=array();

   // add it here as the first item in the array, 
   // assuming you don't have a $row->batchid of 0 in your results.
    $data[0] = 'SELECT'; 

   fo开发者_运维百科reach ($records->result() as $row)
  {
    $data[$row->batchid] = $row->batchname;
  }

return ($data);
} 

And this in my view file

<?php echo form_dropdown('batchid', $dropdown_batchlist,'', 'class="required"' ); ?>

The Problem is Solved

I have figured out the problem. The view file was okay, all I had to do is replace $data[0] = 'SELECT'; with $data[' '] = 'SELECT';

Thanks


Try setting the attributes using an associative array:

$attributes = array(
    'name' => 'batchid',
    'class' => 'required',
    'options' => $dropdown_batchlist
);
echo form_dropdown($attributes);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号