I have a doubt in a form I need that a checkbox field run a small javascript function, what is the best approach to add this javascript code in my file?
At the moment I have 2 options:
- create the function directly on the code, this is more readble than option 2
<script>
function myfunction{
//do something
}
</script>
- use the php function (registerJs) to add the code,
<?php
$this->registerJs("function myfunction{
//do something
}");
?>
What is the best approach? If there are other better option please tell me