Yii Menu

Here is my code for menu,


$this->menu=array(array('label'=>'Test', 'url'=>array('search/index','op'=>'export')));

Till now, i was redirecting on clicking on this, but i want to call javascript function like,


$this->menu=array(array('label'=>'Export to Excel', 'onclick' => 'javascript: alert("Hello");') );

Is it possible?




$this->menu=array(array('label'=>'Export to Excel', 'linkOptions'=>array( 'onclick' => 'javascript: alert("Hello");') ) );



Red,

Thanks for the reply, It’s Working fine, but lost the look and feel. :(

If we pass normal params, then it creates anchor tag, when i tried to call javascript function, it creates span tag and apply the onclick function on that.

actually i want to to do like,


<li><a href="javascript:void(0);" onclick="javascript:alert(1);">Export to Excel</a></li>

Set an id to the item. Then, register a new script with a code like $(’#export-excel’).click(function(){alert(’!!!’);});

Thanks sensorario for the reply !!

Solved it by Other Way !!!!


 $this->menu=array(array('label'=>'Export to Excel', 'url'=>'', 'linkOptions'=>array('onclick'=>'javascript: alert("Hello");','style' => 'cursor:pointer;')));



Give attention to ‘url’=>’’

rather try to specify url parameter also:




$this->menu=array(array('label'=>'Export to Excel', 'url'='javascript:void(0);', 'linkOptions'=>array( 'onclick' => 'javascript: alert("Hello");') ) );



Red,

Yes u r also right… and i think your solution is better than ma as keep url blank is not good.

again thanks!!!