Detect user's output from the text box

1

I have a text box that shows the remaining characters, how do I get that information, using javascript, when the user has already clicked on another text box (for example)?

HTML box and counter:

<textarea maxlength="210" rows="5" id="aboutPT" style="display: none; resize: none" name=""
 class="valid form-control">@dataAbout.PT</textarea>


 <p class="pull-right" id="count_message" style="margin-top: 10px; font-size:small"></p>

Script:

$('#overLimit').hide();

    $('#aboutPT').keyup(function countPT () {
        var text_length = $('#aboutPT').val().length;
        var ptRemaining = text_max - text_length;


        $('#count_message').html('<span class="label label-default">' + ptRemaining + '</span>' + ' @ResourcesHelper.GetResource(strValorSession, "remainingChars")');
    });
    
asked by anonymous 14.02.2017 / 12:18

2 answers

0

Solution

To hide the information of the remaining characters when I exit from textArea I used the .focusout () event. It is very simple, I leave an example below:

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>focusout demo</title>
  <style>
  .inputs {
    float: left;
    margin-right: 1em;
  }
  .inputs p {
    margin-top: 0;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><divclass="inputs">
  <p>
    <input type="text"><br>
    <input type="text">
  </p>
  <p>
    <input type="password">
  </p>
</div>
<div id="focus-count">focusout fire</div>
<div id="blur-count">blur fire</div>

<script>
var focus = 0,
  blur = 0;
$( "p" )
  .focusout(function() {
    focus++;
    $( "#focus-count" ).text( "focusout fired: " + focus + "x" );
  })
  .blur(function() {
    blur++;
    $( "#blur-count" ).text( "blur fired: " + blur + "x" );
  });
</script>

</body>
</html>
    
14.02.2017 / 13:32
0

The event blur is done exactly for this:

$(() => {
   $( '#aboutPT' ).blur(() => {
      $( '#count_message' ).hide(/*duracao em ms/fast/slow/nada*/);
   })
})

Note: where does this id come from? (I find it irrelevant to your question)

$('#overLimit').hide();
    
17.02.2017 / 18:32