Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change a Javascript character-remaining counter, with an onClick?
    primarykey
    data
    text
    <p>Hello :) I have an HTML text area with a Javascript character counter. I want the remaining character count to be reduced by 23 characters when someone clicks the "Browse" button to add media to the text area they are writing. I'm using PHP too. How can I do it? :) </p> <p>Here is the HTML </p> <pre><code> &lt;form id="form" method="post" action="" enctype="multipart/form-data"&gt; &lt;div&gt; &lt;label for="message2"&gt;Type your message&lt;/label&gt; &lt;textarea ID="message2" onkeyup="textCounter(this,'counter',140);" name="status"&gt;&lt;/textarea&gt; Add Picture&lt;input type="file" name="image" /&gt;&lt;br /&gt; &lt;input class="button" type="submit" value="Tweet" /&gt;&lt;br /&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>And the Jquery</p> <pre><code> &lt;script&gt; $(document).ready(function(){ $("#message2").charCount({ allowed: 140, warning: 10, counterText: '' }); }); </code></pre> <p></p> <p>And the CharCount.js</p> <pre><code> (function($) { $.fn.charCount = function(options){ // default configuration properties var defaults = { allowed: 140, warning: 25, css: 'counter', counterElement: 'span', cssWarning: 'warning', cssExceeded: 'exceeded', counterText: '' }; var options = $.extend(defaults, options); function calculate(obj){ var count = $(obj).val().length; var available = options.allowed - count; if(available &lt;= options.warning &amp;&amp; available &gt;= 0){ $(obj).next().addClass(options.cssWarning); } else { $(obj).next().removeClass(options.cssWarning); } if(available &lt; 0){ $(obj).next().addClass(options.cssExceeded); } else { $(obj).next().removeClass(options.cssExceeded); } $(obj).next().html(options.counterText + available); }; this.each(function() { $(this).after('&lt;'+ options.counterElement +' class="' + options.css + '"&gt;'+ options.counterText +'&lt;/'+ options.counterElement +'&gt;'); calculate(this); $(this).keyup(function(){calculate(this)}); $(this).change(function(){calculate(this)}); }); }; </code></pre> <p>})(jQuery);</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload