Link to home
Start Free TrialLog in
Avatar of danny62
danny62

asked on

How do I create a Javascript program that limits the amount of text entered into a text area box

I am fairly new to Javascript. I have only been doing it for about a year. I need help. I have this project and I am lost. I have attached the file
booktxt.htm
comtxt.js
Avatar of danny62
danny62

ASKER

Hi! Nice to meet u
Avatar of danny62

ASKER

Thank you. However, the rest of my project is: declare a global variable named maxLength and set its value to 500, and then have the browser run the init() function when the page is loaded. Create the init() function. Add the commands to the function: Create a variable named commentBox that points to the tevtarea element with the ID element.  Create a variable named contBox that points to the ID wordcount. Set the value of countBox to the textstring 0/maxlength,where maxlength is the value of the maxlength variable.Call the checkLength() function whenever the user presses the keyboard key within the commentBox object.Create the countText() funtion.Add the following commands: Declare a variable a variable named commentBox that references the comment text are box.Store the regular expression /\s/g in the variable commentregx. This regular expression selects all of the white space characters within a specified text string. Use the regular expression replace() method to replace every occurrence of white space characters within the commentBoax object with an empty text string in a variable named commentText.Return the length of the commentText variable.Create the checkLength() function.Declare a variable named evt that points to the event object under either event model. Set an if statement with the following conditions: (i)If the value returned by the countText() function is less than maxlength, then return the value true; (ii)else if the user has typed the Backspace key or the Delete key, return the value true; (iii) otherwise, return the value false.Create the updateCount() function.Add the following commands: declare the countBox variable that references the input element with the ID wordcount. Set the value of the currentLength variable returned by the countText() function. Set the value of the countBox object to the text string currentLength/maxLength,where currentLength is the value of the currentLength variable and maxLength is the value of the maxLength variable. If currentLength is less than maxLength, set the font color of the text in the countBox object to black with a background color of white; otherwise, set the font color to white on a red background. Thank you
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of danny62

ASKER

not homework