ok, one more shorter try: it works! $(document).ready(function(){ $("#couponCode").blur(function(){ $("#couponCode").val($(this).val().toUpperCase().replace(/\s+ $/,'')); }); });
On May 13, 12:53 pm, jckos <johncar...@gmail.com> wrote: > 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.