how to use my own js file

I create a button in a form , I want to call a function in a js file.

how to do.

  1. in user.php(view)

<?php

Yii::app()->clientScript->registerScriptFile(Yii::app()->basePath.'/js/test.js');

?>

<?php

  echo CHtml::button('test script',array('click','test'=>'tested string'));

?>

  1. test.js

function test(dd)

{

&#097;lert(dd);

}

Is it right if I write like this?

Change 'basePath' to 'baseUrl'.

Change 'click' to 'onclick'.

qiang ,it does not work. any other suggestion?

What's the generated HTML?

1.for the js file

<script type="text/javascript" src="/js/test.js"></script>

2.for the button

<input 0="onclick" test="tested string" name="yt1" type="button" value="test script"/>

The htmlOptions parameter to CHtml::button is incorrect. It should be an array of name-value pairs that you want to generate as attributes in the input tag.

1.source code

  <?php

  echo CHtml::button('test script',array('click','test'=>'tested string'));

?>

2.the html result is :

<input 0="onclick" test="tested string" name="yt1" type="button" value="test script"/>

you mean that the result should be

<input 0=“onclick” test=>“tested string” name=“yt1” type=“button” value=“test script”/>

can u give me an example?

echo CHtml::button('test script',array('onclick'=>'myFunction(1337)'));

will produce

  <input onclick="myFunction(1337)" name="yt0" type="button" value="test script"/>

they are HTML options, meaning they are just adding attributes to the input tag.

thanks DarkNSF

got u