PDA

View Full Version : :: limit the size of input on form fields? ::


babelfish
08-30-2002, 11:35 AM
http://www.simonsgroup.com/IT/DEVELOPMENT/liam.nsf/requestbrochureform

on that page i have 2 textarea input fields - now, i have tried size="x" and maxlength="x" but they dont seem to work - basically i just dont want ppl to copy and paste the entire works of william shakespear into them - as that would make the Dbase cough a little :)

any ideas? is this a jscript option?

boxer_1
08-30-2002, 12:04 PM
Hi Babelfish, here's a script you may be interested in having a look at:

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

babelfish
08-30-2002, 12:12 PM
ive seen one like that b4 - its really more complex than neeeded - basically i just want the field's contents limiting to 100 chars - so if i can just add a simple script like limitfield(25); that would be great - im working on something now but my feeble jscript prowess is letting me down ;)

babelfish
08-30-2002, 03:19 PM
in the end i settled for:

<SCRIPT LANGUAGE="JavaScript">
function textlimit(fieldname, fieldsize) {
fieldname == 'this.form.' + fieldname;
if (fieldname.value.length > fieldsize) {
alert('You have typed too much into this field \n Please make the input more concise \n This field is limited to ' + fieldsize + ' characters');
fieldname.value = fieldname.value.substring(0, fieldsize);
}
}
</script>

<form name=myform action="something">
<textarea name=message wrap=physical cols=28 rows=4 onKeyUp="textlimit(message,25);"></textarea>
</form>

i would like to dynamically grab the actual fieldname if poss - but i havent figured out how to do that :(

boxer_1
08-30-2002, 05:34 PM
Glad to see you've solved the problem Babelfish (well, except for 1 issue). Thanks for taking the time to post the solution you settled for here. It may prove helpful to someone else in the event that they turn up this thread in a search if another member has a similar issue :).

joh6nn
08-31-2002, 12:39 AM
noticed a small error in your code, ( line 2 ), turned it into this. didn't test it, but it should be good.

<SCRIPT LANGUAGE="JavaScript">
function textlimit(field, fieldsize) {
if (field.value.length > fieldsize) {
alert('You have typed too much into this field \n Please make the input more concise \n This field is limited to ' + fieldsize + ' characters');
field.value = field.value.substring(0, fieldsize);
}
}
</script>

<form name=myform action="something">
<textarea name=message wrap=physical cols=28 rows=4 OnKeyUp="textlimit(this,25);"></textarea>
</form>

babelfish
09-02-2002, 08:57 AM
thanks joh6n