Tuesday, May 8, 2012

JavaScript - Limit the input length as you type, works with TextArea as well

Limit the input length as you type, works with TextArea as well:



<script type="text/javascript">
    function limit_text(limit_field, limit_num) {
        if (limit_field.value.length > limit_num) {
            limit_field.value = limit_field.value.substring(0, limit_num);
        }
    }
</script>


<asp:TextBox ID="tb_new_ad_body" runat="server" TextMode="MultiLine" onKeyPress=" limit_text (this,30);"></asp:TextBox>
                                        



Enjoy!

No comments:

Post a Comment