Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery preventDefault not working in any IE version
    primarykey
    data
    text
    <p>I'm tring to prevent users entering any more input into a textarea when the char count reaches a certain value.</p> <p>My code works fine in Chrome, Safarai and Firefox.</p> <p>But the <strong><em>preventDefault</em></strong> method will <em>not work</em> for me in any version of <strong><em>IE</em></strong>.</p> <p>I have found many similar topics on SO about this and included the most common suggestion:</p> <ul> <li>Performing a check to make sure preventDefault exists. If it doesn not exist use IEs <strong><em>returnValue=false</em></strong>. The problem is <strong><em>returnValue=false</em></strong> will not work either.</li> </ul> <p>Any suggestions?</p> <pre><code>// Attach textarea char counter to all textarea's with class of 'textarea-char-count' $('.textarea-char-count').live("keyup", function(event) { MYAPP.COMMON.textareaCounter(this, event); }); // Attach textarea char counter to element MYAPP.COMMON.textareaCounter = function(element, evt) { //Get char limit var limit = $(element).attr("maxlength"); // get current character count var current = $(element).val().length; // if current character count is greater than or equal to the character limit if(current &gt;= limit) { // prevent further characters from being entered apart from the // Delete and Backspace keys if(evt.which != 0 &amp;&amp; evt.which != 8) { if (evt.preventDefault) { evt.preventDefault(); } else { evt.returnValue = false; } } } // add the remaining character count to our span $(element).parent().next().show().text( current + " / " + limit); } </code></pre>
    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.
 

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