简体   繁体   中英

how to count the number of time of the text that has been entered in a textbox in jsp?

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Connection Unsuccessful</title>
  </head>
  <body>
    <div class="container">
      <label for="uname"><font size="4" color="black"><b>Connection Name</b></font></label> 
      <input type="text" placeholder="Connection Name" name="cname" required>
    </div>
  </body>
</html>

how can i count the numbers of times of the connection name entered in a text box using java?

Do you want to count the number of text characters entered into the input? Or do you want to count how many times the user attempts to enter the connection? I've added even listeners for keyup and blur to count the input length as well as every time the user leaves the input:

 var conName = document.getElementById("conName"); var keyStrokeCnt = 0; var inputCnt = 0; var keyStrokeRes = document.getElementById("keyStrokeResult"); var inputRes = document.getElementById("inputResult"); function start() { conName.addEventListener("keyup", function() { keyStrokeCnt = conName.value.length; keyStrokeRes.innerHTML = "Number of keystrokes entered: " + keyStrokeCnt; }); // conName.addEventListener("blur", function() { inputCnt++; inputRes.innerHTML = "Number of times input: " + inputCnt; }); }; window.onload = start();
 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Connection Unsuccessful</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> </head> <body> <div class="container"> <label for="uname"><font size="4" color="black"><b>Connection Name</b></font></label> <input type="text" id="conName" placeholder="Connection Name" name="cname" required> </div> <div id="keyStrokeResult"></div> <div id="inputResult"></div> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM