Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2005, 11:36 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default put a limit on the number of characters entered in

how to put a limit on the number of characters entered into a text box

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old March 23rd, 2005, 12:26 PM
Authorized User
 
Join Date: Feb 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There's no way to do it in HTML, but I found this page with a Javascript solution:

http://www.html-faq.com/scriptingforms/?limittextarea
 
Old March 24th, 2005, 03:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Set the maxLength property.

--

Joe (Microsoft MVP - XML)
 
Old March 24th, 2005, 05:45 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

"Set the maxLength property."

is that in HTML?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
 
Old March 24th, 2005, 12:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello, I found this a while back that counts the characters entered.

Place in <HEAD>
<SCRIPT LANGUAGE="JavaScript">
function TrackCount(fieldObj,countFieldName,maxChars)
{
  var countField = eval("fieldObj.form."+countFieldName);
  var diff = maxChars - fieldObj.value.length;

  // Need to check & enforce limit here also in case user pastes data
  if (diff < 0)
  {
    fieldObj.value = fieldObj.value.substring(0,maxChars);
    diff = maxChars - fieldObj.value.length;
  }
  countField.value = diff;
}

function LimitText(fieldObj,maxChars)
{
  var result = true;
  if (fieldObj.value.length >= maxChars)
    result = false;

  if (window.event)
    window.event.returnValue = result;
  return result;
}
</SCRIPT>


place in the <BODY>
<FORM ACTION="form.asp" METHOD=POST>
<TEXTAREA NAME="FIELDNAME" ROWS=10 COLS=40 ONKEYUP="TrackCount(this,'textcount',400)" ONKEYPRESS="LimitText(this,400)"></TEXTAREA><BR>
<BR><BR>
<INPUT TYPE="text" NAME="textcount" SIZE="3" VALUE="400"><BR><BR>
</FORM>


Peace
Mike
http://www.eclecticpixel.com
http://www.homegrownmusicjam.com
 
Old March 24th, 2005, 02:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
quote:Originally posted by crmpicco
 "Set the maxLength property."

is that in HTML?
That's what they say.
http://www.w3.org/TR/html401/interac...adef-maxlength

(o<
//\ =^..^=
 
Old April 12th, 2005, 06:08 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

            <input name="remark" type="text" id="remark" maxlength="43" size="45" STYLE="color: black; font: 8pt Verdana, Arial, Helvetica, sans-serif; background-color:#ffffff;border: 1px solid #000000;">


www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Randum number and characters in image using php [email protected] PHP How-To 0 February 27th, 2007 09:29 AM
How do they figure out the number of characters? kenn_rosie VS.NET 2002/2003 1 March 20th, 2006 04:23 AM
Exception Entered mh VB.NET 4 October 18th, 2005 12:12 PM
How to put the version number i'm working on eresina General .NET 2 January 6th, 2005 01:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.