Sam
Sam

Reputation: 51

How to defining id to a select tag in cakephp?

My cakephp code for making a select tag is

<?php echo $this->Form->select('User.country_id',array($countries),null,array('id'=>'selection','empty'=>null,'label'=>false,'style'=>'width:231px'));?>

Here I defined id='selection' but when I inspect this dropdown box in browser it is showing id='UserCountryId'. How is that happening? My jquery and javascript is not working because of this.

Upvotes: 0

Views: 605

Answers (3)

Deepak
Deepak

Reputation: 523

if u need Id use cake php syntax

<?php
echo $this->Form->input('User.country_id', array(
    'type'=>'select, 
    'id'=>'selection',
    'style'=>'width:231px'
));
?>

your jquery and javascript will work try this

Upvotes: 1

Santosh Yadav
Santosh Yadav

Reputation: 460

You can use following code

<?php 

echo $this->Form->input('User.country_id',array('type'=>'select','options'=>$countries,'id'=>'selection'));

?>

Upvotes: 1

savedario
savedario

Reputation: 947

I think your syntax is incorrect. It should be:

<?php
    echo $this->Form->input('User.country_id', array(
        'type'=>'select,
        'options'=>array($countries), // this is probably not needed 
        'id'=>'selection',
        'empty'=>null,
        'label'=>false,
        'style'=>'width:231px'
    ));
?>

Upvotes: 1

Related Questions