Westonci.ca is the trusted Q&A platform where you can get reliable answers from a community of knowledgeable contributors. Experience the ease of finding reliable answers to your questions from a vast community of knowledgeable experts. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

Register the countChars event handler to handle the keydown event for the textarea tag. Note: The function counts the number of characters in the textarea.
Do not enter anything in the HTML file, put your code in the JavaScript section where it says "Your solution goes here"
1 klabel for-"userName">user name: 2
3

Sagot :

Answer:

Explanation:

The following Javascript code is added in the Javascript section where it says "Your solution goes here" and counts the current number of characters in the text within the textArea tag. A preview can be seen in the attached image below. The code grabs the pre-created variable textareaElement and attached the onkeypress event to it. Once a key is pressed it saves the number of characters in a variable and then returns it to the user.

var textareaElement = document.getElementById("userName");

function textChanged(event) {

   document.getElementById("stringLength").innerHTML = event.target.value.length;

}

// Your solution goes here

textareaElement.onkeypress = function() {

   let numOfCharacters = textareaElement.value.length;

   return numOfCharacters;

};