How to implement the deletion of the last character entered in the textarea at the event keyup?
Closed due to the fact that the issue is too common for the participants of Streletz , cheops , tutankhamun , Grundy , Kirill Stoianov Sep 30 '16 at 15:26 .
Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Should any character entered be deleted? - Ruslan_K
- @Ruslan_K Yes, any - Vladimir Alexandrov
|
1 answer
$('#idOfTA').keyup( function(){ var inputString = $('#idOfTA').val(); var shortenedString = inputString.substr(0,(inputString.length -1)); $('#idOfTA').val(shortenedString); }); $('#idOfTA2').keyup( function(){ var max = 5; var len = this.value.length; //alert(len); if(len > max) { var inputString = $('#idOfTA2').val(); var shortenedString = inputString.substr(0,(inputString.length -1)); $('#idOfTA2').val(shortenedString); } }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="#" method="post"> <label for="idOfTA">Текст:</label> <textarea id="idOfTA" ></textarea> <br/> <label for="idOfTA2">Текст(не более 5ти символов):</label> <textarea id="idOfTA2" ></textarea> </form> - Thank you so much that I was stupid) - Vladimir Alexandrov
|