Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2003, 04:52 AM   PM User | #1
alaios
Regular Coder

 
Join Date: Aug 2002
Posts: 433
Thanks: 3
Thanked 0 Times in 0 Posts
alaios is an unknown quantity at this point
max length

i have a textarea...and i want to let the uesr to enter only 10 characters....how i can do it? I know how to do this in a input text but i dont know in a textarea
alaios is offline   Reply With Quote
Old 02-21-2003, 05:06 AM   PM User | #2
justame
Regular Coder

 
Join Date: Jun 2002
Posts: 676
Thanks: 1
Thanked 0 Times in 0 Posts
justame is on a distinguished road
ala...
/me has this just a copied/pasted/credited® n' saved from the ol' wa forum...:O)))

just a goodluck® n' hoping it helps...:O)))

Code:
Description: A script that checks the number of characters in a form box, and if it exceeds the predetermined number,
cancels the form submission, and asks the surfer to reenter data.

Example: 

In 50 chars or less, please type a short description of yourself:
                                          
          

Directions: Simply cut and paste the below code into the <body> section of your page. It contains a form with one textarea
box that is checked for max # of characters. You can change this # from the default 50 to another by changing "var maxlength"
below. You can add in more form elements into the form, as you would with any other form.

<script>
<!--

/*Form Characters check script credit-Website Abstraction (www.wsabstract.com) 200+ free JavaScripts here!
*/

function checkchars(cur){
//change max length to determine below
var maxlength=50
if (cur.chars.value.length>maxlength){
alert("Please restrain your input to 50 or less characters!")
return false
}
}
//-->
</script>

<form onsubmit="return checkchars(this)">
<strong>In 50 chars or less, please type a short description of yourself:</strong><br><textarea rows="5" cols="38" name="chars"></textarea>
<br><input type="submit" value="Submit!">
</form>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://wsabstract.com">Website
Abstraction</a></font></p>
justame is offline   Reply With Quote
Old 02-22-2003, 01:22 PM   PM User | #3
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
I wrote a more cross-browser script here:

http://www.solidscripts.com/displayscript.asp?sid=1

Code:
<script type="text/javascript">
<!--
/*****************************
Maxtext v1.2
Copyright 2002 Robert K. Davis
******************************/
function getlength(x,y){
   return x < y;
}
function textlen(x,y){
   var thelength = x.value.length;
   window.status = thelength + " of " + y + " maximum characters.";
}

function maxtext(x,y){
   var tempstr = x.value;
   if(tempstr.length > y){
      x.value = tempstr.substring(0,y);
      alert("Please limit your entry to " + y + " characters or less.");
   }
   textlen(x,y);
}
/*********************/
// -->
</script>
This uses a number of different techniques and it has been tested in Opera, Mozilla, Netscape 4.x, Netscape 6+, and IE.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:28 AM.


Advertisement
Log in to turn off these ads.