Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Javascript to limit description field input?

Quote Reply
Javascript to limit description field input?
Hi,

I want to limit the length of a site's description when submitted and wondered if anyone has a javascript snippet I could use for the textarea form field?

I'm currently using a basic single line input form field with a maxlength setting, but its not very user friendly and I'd prefer to give my visitors a textarea box so they can see all of what they've typed.

I've tried a few examples I found on the web, but they didn't seem to work.

Any help appreciated.

All the best
Shaun
Quote Reply
Re: [qango] Javascript to limit description field input? In reply to
I'm assuming this is for the user side of the admin, and not the admin addition side of it?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [qango] Javascript to limit description field input? In reply to
How about the following. I think this only works in IE

http://www.dynamicdrive.com/...dex16/limitinput.htm

------------------------------------------
Quote Reply
Re: [qango] Javascript to limit description field input? In reply to
We are using this Javascript (which we think is based on something we found in this forum, somewhere)

Code:
function fmaxlen(input, max, fname) {
var q = eval("document.dirform." + input + ".value.length");
var r = q - max;
var msg =
"Sorry, you have used " + q + " characters in form field \"" + fname + "\".\nThe maximum length of this field is " + max + " characters.\nPlease abbreviate your text by at least " + r + " characters";
if (q > max) {
alert(msg);
}
}

Example usage:
Code:
<FORM NAME="dirform" ACTION="<%db_cgi_url%>/add.cgi" METHOD="POST">
...
<TEXTAREAWRAP="VIRTUAL" NAME="Description"
ONCHANGE="fmaxlen('Description', 1023, 'Description')"
ROWS="8" COLS="50"><%if Description%><%Description%><%endif%></TEXTAREA>