Well, you could try using a text transform CSS attribute on the text field. Then you wouldn't have to perform a toUpperCase using JavaScript. But other than that, looks about as lean as you can get it.
andy -----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of jckos Sent: Wednesday, May 13, 2009 11:53 AM To: jQuery (English) Subject: [jQuery] Better way to trim whitespace from input? Hi, I need to transform all characters entered in an input field to uppercase and trim trailing whitespace. This script works, but I'm wondering if there's a better way to do it. <script> $(document).ready(function(){ $("input").keyup(function (e) { $("#couponCode").val($(this).val().toUpperCase()); }); $("button").click(function () { var couponCode = $("#couponCode").val(); couponCode = jQuery.trim(couponCode); }); }); </script> Any suggestions? Thanks in advance.