The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: Max Length [JS Class]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: maxLength
Programming Language: JavaScript
Date Completed: 2012/09/24

Purpose: To restrict or force a Web browser to restrict the maximum input length for a field.

Description: Not all Web browsers can restrict the text length limit of an input field. This JavaScript class can force virtually all Web browsers to restrict the input size.

Compatibility: Works with all Web browsers.
Special Note: Does not work with Opera 6 and older.

Advertisement

Donate Now!

I don't always use the women's bathroom, but when I do, you can bet it really smells. If you like my blog, please consider donating.


Methods:

var class = new maxLength();

class.targetId;Assign limit to element ID
class.max;Assign the max character limit
class.length;Returns the current number of characters
class.start();Function to start the listeners
class.stop();Function to stop the listeners

Max:

Default value 0 if HTML attribute maxlength is not set or if the Web browser does not support reading HTML attributes. Set this value if you feel your Website visitors maybe using legacy Web browsers or you have not set the maxlength attribute.

If the max value is set higher than the maxlength attribute, the maxlength attribute will be set to match. However, if the maxlength attribute is not set, it will be set with the max value.

Example Usage:

HTML

<textarea id=”mytxtArea” rows=”4″ cols=”30″ maxlength = “16”></textarea>

Java Script

var textBox1 = new maxLength();
textBox1.targetId = “mytxtArea”;
textBox1.start();

 

Advertisement

Donate Now!

Hey buddy, it takes a lot to make a blog. How about a donation?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.