11

Is there any possible way of adding class and id attributes in form_dropdown of CodeIgniter? I tried form_dropdown('name',$array,'class','id') and it's not changing anything, please tell me how to implement it?

Edited:
with my dropdown form like this form_dropdown('name',$array,set_value('someValue'),'id="myId"'); if I see my source from my browser it's look like this <select name="provinsi" id="provinsi_id">, but if I write like your way form_dropdown('name',$array,set_value('someValue'),'class="myClass"','id="myId"'); than like this in my browser source <select name="provinsi" class="myClass">

that was I mean
thank you

Rivnat
  • 1,497
  • 1
  • 20
  • 34
ranggadablues
  • 249
  • 1
  • 4
  • 14

2 Answers2

35

Like this:

form_dropdown('name', $array, '', 'class="my_class" id="my_id"')

The third parameter is for the value you wish to be selected and the fourth is for the additional data. Read more.

Yan Berk
  • 14,328
  • 9
  • 55
  • 52
  • hi thanks @Yan for your time to answer my question, when I try like you way than I can't see for `id` tag..any suggestion? – ranggadablues Jun 21 '12 at 09:09
  • Remove the comma. Like this: `'class="myClass" id="myId"'`. You need to seperate them only by space. Adding a comma makes the id a fifth parameter which the `form_dropdown` function doesn't have. – Yan Berk Jun 21 '12 at 10:06
  • hahahaha..so stupid me, I did not notice it..thank you it's works now – ranggadablues Jun 21 '12 at 10:22
0

You can defined class, id or any other HTML attribute in the forth parameter of form_dropdown() function as an associative array like below:

form_dropdown('name', $array, set_value('someValue'), ['class' => 'myClass', 'id' => 'myId']);

Usman Ahmed
  • 2,392
  • 1
  • 20
  • 17