The vBulletin templating system is actually quite flexible easy to use (once you get the hang of it). Add this to your template:
Code:
<script type="text/javascript">
//<![CDATA[
var myVar1 = <if condition="isset($myPhpVar1)">$myPhpVar1<else />$myPhpVar1Default</if>;
var myVar2 = <if condition="isset($myPhpVar2)">$myPhpVar2<else />$myPhpVar2Default</if>;
var lenght = 25;
function func(){
if (length > $lengthPHP)
{
document.getElementById('myID').value = document.getElementById('myID').value.substring(0, $lengthPHP);
}
}
//]]>
</script>
BTW, you spelt "length" wrong. I've corrected this in your code (you will need to adjust your other code, potentially).