I have a some simple code igniter PHP code that I wish to validate to ensure that only 10 chars max can be typed in the Text area. I wish to use JavaScript for the validation. How can I integrate the both?
Below shows the PHP/codeigniter and rough javascript code that I am going to use.
Can I add the javascript as a 3rd parameter in the echo form_textarea method as described here?
PHP:
echo form_textarea('age',set_value('age',0));
JavaScript:
<script language="javascript" type="text/javascript">
function limitText(limitField,limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
}
}
</script>
So would the following work? :
$js = 'onKeyDown="limitText(age,10)"';
echo form_textarea('age',set_value('age',0),$js);