var zoomy = "\n\

Text box length limits

\n\
\n\ \n\

\n\ \"\" \n\

\n\ \n\

\n\ Here's a quick way to limit the length of customer comments on your invoices using javascript. Essentially, this is just a script to limit the size of a <textarea> element. This can be handy when you need to make sure a text field doesn't have too much text in it…\n\

\n\ \n\

\n\ in both includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_shipping_default.php and includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_payment_default.php\n\

\n\ \n\

\n\ find this line (might be different depending on your template)\n\

\n\
<?php echo zen_draw_textarea_field(\'comments\', \'45\', \'3\'); ?>
\n\ \n\

\n\ and insert BENEATH it\n\

\n\
Max  140 Characters (<div style="display:inline" id="charCount">140</div> remain)\n\
<script>\n\
comments = document.getElementsByName("comments")[0];\n\
 \n\
// Cover all your bases just to be sure\n\
comments.onkeydown = commentstuff;\n\
comments.onkeypress = commentstuff;\n\
comments.onkeyup = commentstuff;\n\
comments.onblur = commentstuff;\n\
comments.onfocus = commentstuff;\n\
comments.onclick = commentstuff;\n\
comments.onselect = commentstuff;\n\
function commentstuff(){\n\
if (comments.value.length > 140)\n\
    {\n\
      comments.value = comments.value.substring(0, 140);\n\
    }\n\
  remain = 140 - comments.value.length;\n\
  document.getElementById(\'charCount\').innerHTML = remain;\n\
}\n\
  remain = 140 - comments.value.length;\n\
  document.getElementById(\'charCount\').innerHTML = remain;\n\
</script>
\n\ \n\

\n\ And you're done! Of course, this is pretty easy to hack (you could just turn off javascript in your browser). If you really need to limit this field legitimately you should probably do it server-side in the php. \n\

\n\ \n\
\n\ ";document.write(zoomy);document.write("

This page was autogenerated from http://www.ladyada.net/wiki//tutorials/zencartmods/comments_max_length.html
Please edit the wiki to contribute any updates or corrections.
")