View Full Version : Form input limiting
darkannie
04-29-2003, 01:26 PM
i saw this on the Dynamic html website, but the one they offer comes with a validator, which i have the least interest in. all i want is to limit the form to 1000 words. like i said before, i run a story submission website and i have this box for sample submissions and i don't want someone submitting an entire 30 or forty page story into that textbox. no matter what, people seem to overlook when i tell them one is for HTML submission, the other is for samples that HTML is not required for. Because I allow full submission in the HTML box, one person mistook that for a complete submission sans HTML. i don't like getting complete submissions from people through the form without html because of format. like italics and paragraph breaks. so if there's a way to limit word-count to 1000 or whatever number i want, i'd appreciate the help.
tamienne
04-29-2003, 01:36 PM
I saw this on a different site...
http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/32/pid/215/qid/534184
requestcode
04-29-2003, 01:45 PM
If you are using a textarea here is an example of one way to do it:
<html>
<head>
<title>Word Count</title>
<script language="JavaScript">
function countit(fldobj,max)
{
var count=0
var len=0
var formcontent=fldobj.value // grab the text from the textarea
formcontent=formcontent.split(" ") // split the words into an array
for(i=0;i<formcontent.length;i++)
{
if(formcontent[i]=="") // Count the number of spaces or nulls
{
count++
}
}
len=formcontent.length-count // subtract spaces or nulls from the length
window.status="You have entered "+len+" words."
if(len>max)
{alert(max+" is the max!")}
}
</script>
</head>
<body bgcolor="lightgreen" onload="document.myform.reset()">
<form name="myform">
<center>
<br>
<h2><font color="red">Word Count</font></h2>
<textarea rows="5" name="adtext" cols="30" WRAP="hard" onkeydown="return countit(this,20)"></textarea>
</center>
</form>
</body>
</html>
beetle
04-29-2003, 02:27 PM
Do you want to count actual words, or typographical words (5-letters, no spaces) ?
darkannie
04-29-2003, 09:54 PM
is there anyway i can stop the characters from simply appearing once it's gotten its limited amount of words? the pop-up was cool but i just need something that will limit, not be snotty. lol!
i guess i need something that will block characters rather than whole words. let me know.
Kylena
09-30-2003, 07:04 AM
Found this, it will limit the number of characters:
function textCounter(field, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
}
<textarea name="message" onKeyDown="textCounter(this.form.message, 125);" onKeyUp="textCounter(this.form.message, 125);"></textarea>
Hope it helps.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.