Here I explained How to add user javascript into yii using clientscript->registerScript function with example.
Create Client Script
<?php /** * Create Client Script **/ Yii::app()->clientScript->registerScript("newdownloadbtnjs",' /** enter your js code here **/ '); ?>
Client Script With Button Action
<?php /** * Client Script With button action * */ Yii::app()->clientScript->registerScript("newdownloadbtnjs",' /** enter your js code here **/ $("#buttonid").live("click",function(){ alert("welcome"); }); '); ?>
Client Script For User Ajax Request
<?php /** * Client Script With Ajax Request * */ $siteurl=Yii::app()->createAbsoluteUrl("site/index"); Yii::app()->clientScript->registerScript("scriptjs",' $("#buttonid").live("click",function(){ /** ajax Start **/ var thisid=1; $.ajax({ "url":"'.$siteurl.'", "type":"POST", "data":"userid="+thisid, "success":function(data){ var jsonobj=jQuery.parseJSON(data); var status=jsonobj["status"]; if(status==1){ alert("success"); } } }); /** ajax end **/ }); '); ?>