Script limits words in a textarea. Issue when reselecting option (larger) - always triggers first/smaller option help needed to provide reset
<p>Original script was from <a href="http://bavotasan.com/2011/simple-textarea-word-counter-jquery-plugin/" rel="nofollow">http://bavotasan.com/2011/simple-textarea-word-counter-jquery-plugin/</a></p>

<p>Simple modifications were made to include using the select function to set the word limitation. with my limited knowledge and using the console function, the b.limit does not get reset leaving multiple occurances of it depending on the number of times you use the select option. </p>

<pre><code>        (function (a) { 

       a.fn.textareaCounter = function (b) { 
         $('input[name="AddToCart_Submit"]').val("Order cake");
        var textCount = $("#moc").text(); 
        $(':input').val('');

    switch (textCount) {
    case "Message on Cake (message limited to 4 words)":
        $('span[id^="counter-text"]').remove();
        var c = {limit: 4  };
        break;
        case "Message on Cake (message limited to 5 words)": 
        $('span[id^="counter-text"]').remove();
        var c = {limit: 5  };
        break;
    case "Message on Cake (message limited to 6 words)":
            $('span[id^="counter-text"]').remove();
            var c = {limit: 6  };
        break;
    case "Message on Cake (message limited to 9 words)":
        $('span[id^="counter-text"]').remove();
        var c = {limit: 9  };
        break;
        case "Message on Cake (message limited to 22 words)":
        $('span[id^="counter-text"]').remove();
        var c = {limit: 22  };
            break; 
        }
          var b = a.extend(c, b);
            return this.each(function () {  
            var c, d, e, f;
         $('input[name="AddToCart_Submit"]').val("Order cake");

            c = a(this);

            c.after('&lt;span style="clear: both; margin-top: 3px; display: block;" id="counter-text"&gt;Max. ' + b.limit + " words&lt;/span&gt;");
            c.keyup(function () {
                d = c.val();
            regex = /\s+/gi;
            value = c.val();
                if (d === "") {
                            e = 0
                        }
            else {
            e = a.trim(d).split(" ").length
                  }
              if (e &gt; b.limit) {
                    a("#counter-text").html('&lt;span style="color: #DD0000;"&gt;0 words left&lt;/span&gt;');
                    f = a.trim(d).split(" ", b.limit);
                    f = f.join(" ");
                    a(this).val(f)
                } else {
                    a("#counter-text").html(b.limit - e + " words left")
                }
            })
        })
    }

})(jQuery)
</code></pre>
