I'm attempting to set the maxlength value of a textbox to the length of a string using javascript, but the maxlength doesn't change at all.
<input name="answerTxt" type="text" class="form" id="answer" onkeypress="do_enter(event);" onkeyup="count('answer');" size="25" maxlength="5">
<script>
var txt = "hello"
document.getElementById('answer').maxlength = txt.length
</script>