I have a textarea element in a Facebook application I want to limit, visually, to a certain number of characters. This is a code snippet I got from the web:
<script>
function textCounter(textarea, countdown, maxlimit)
{
textareaid = "ta1";
if (textareaid.value.length > maxlimit)
textareaid.value = textareaid.value.substring(0, maxlimit);
else
document.getElementById(countdown).value = '('+(maxlimit-textareaid.value.length)+' characters available)';
}
</script>
<form>
<textarea id="ta1" name="ta1" rows=5 cols=20
onKeyDown="textCounter('ta1','ta1count',100);"
onKeyUp="textCounter('ta1','ta1count',100);"
></textarea>
<br/>
<input id="ta1count" readonly type="text" size="30"/>
</form>
<script type="text/javascript">
textCounter('ta1','ta1count',100);
</script>
This script works well outside of a Facebook frame, but I don't understand the limitations of FBJS and what I'd need to change to make this script work. Has anyone had success implementing a similar feature?
Thanks.