Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Looking for JavaScript to enable form submit button after X characters

Validate minimum content

3:28 pm on Apr 10, 2009 (gmt 0)

New User

10+ Year Member

joined:Dec 17, 2006
posts: 33
votes: 0

Hi Folks...

Not a JavaScript expert here... but I've been looking for an example script that would validate text-area content by character count, not allowing the form to be submitted until a minimum of X characters had been typed.

Does anyone have any guidance on this one?

Thanks in advance.

6:47 pm on Apr 10, 2009 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Use the string length property of the element value. Something like ...
var el = document.getElementById('myTextArea'); 
if (el.value.length > 75) {
// good to go
} else {
// I need more information
1:44 pm on Apr 13, 2009 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
votes: 0

// note that I'm using the $() shortcut here... because I'm lazy

var el = $('myTextArea');
var sb = $('mySubmitButton');

// have the behaviour trigger on keyup for best user responsiveness
// the length condition returns true or false.
// assign that to the "disabled" property of your submit button

el.onkeyup = function(){
sb.disabled = (this.value.length < 75);