Hey all,
The following function counts for number of characters in a text area
and displays
error msg when it exceeds a maximum limit
I would like to optimize this function so that its highly portable
and elegant
if anybody could do. It will be of great help. Also I would like to add
mincount
ie: a text less than mincount should raise error
----------------------
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="Javas cript">
function checkchars(txtA rea,maxLength)
{
txtArea.value = txtArea.value.s lice(0, maxLength);
if(txtArea.valu e.length>=maxLe ngth)
{
alert('Only 20 Characters are Allowed');
}
//Display Remaining characters can type in TextBox
document.getEle mentById('txtDi splay').value =maxLength -
txtArea.value.l ength
}
</script>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40"
onkeyup="checkc hars(this,20)"> </TEXTAREA>
No of Characters Allowed: <INPUT TYPE="TEXT" name="txtDispla y"
id="txtDisplay " value=20 MaxLength=3 disabled=disabl ed
style="width:25 px;border=0" > <BR>
</BODY>
</HTML> 4 2234 pr**********@gm ail.com wrote: Hey all, The following function counts for number of characters in a text area and displays error msg when it exceeds a maximum limit I would like to optimize this function so that its highly portable and elegant if anybody could do. It will be of great help. Also I would like to add mincount ie: a text less than mincount should raise error ---------------------- Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script language="Javas cript"> function checkchars(txtA rea,maxLength) {
txtArea.value = txtArea.value.s lice(0, maxLength);
The line above is unneeded and destructive...
Why notthe following?
function checkchars(txtA rea,maxLength){
if(txtArea.valu e.length>=maxLe ngth){
alert('Only '+maxLength+' characters are allowed.');
}
}
<TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40"
onkeyup="checkc hars(this,this. form.txtDisplay .value)"></TEXTAREA>
Mick
if(txtArea.valu e.length>=maxLe ngth) { alert('Only 20 Characters are Allowed'); }
//Display Remaining characters can type in TextBox document.getEle mentById('txtDi splay').value =maxLength - txtArea.value.l ength } </script> <TITLE> New Document </TITLE>
</HEAD>
<BODY> <TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40" onkeyup="checkc hars(this,20)"> </TEXTAREA> No of Characters Allowed: <INPUT TYPE="TEXT" name="txtDispla y" id="txtDisplay " value=20 MaxLength=3 disabled=disabl ed style="width:25 px;border=0" > <BR> </BODY> </HTML>
mick white wrote: pr**********@gm ail.com wrote:
Hey all, The following function counts for number of characters in a text area and displays error msg when it exceeds a maximum limit txtArea.value = txtArea.value.s lice(0, maxLength);
The line above is unneeded and destructive...
Why notthe following? function checkchars(txtA rea,maxLength){ if(txtArea.valu e.length>=maxLe ngth){
/* if(txtArea.valu e.length>maxLen gth) */
Mick alert('Only '+maxLength+' characters are allowed.'); } } <TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40" onkeyup="checkc hars(this,this. form.txtDisplay .value)"></TEXTAREA>
Mick
What does this piece do ?
-----------------------------------
<TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40"
onkeyup="checkc hars(this,this. form.txtDisplay .value)"></TEXTAREA>
-------------
I guess checkchars() uses the value from this textbox
Is that right ? pr**********@gm ail.com wrote: What does this piece do ? ----------------------------------- <TEXTAREA name="txtAreaRe sume" rows="5" wrap="VIRTUAL" cols="40" onkeyup="checkc hars(this,this. form.txtDisplay .value)"></TEXTAREA> ------------- I guess checkchars() uses the value from this textbox Is that right ?
It passes the value of "txtDisplay " to the checkchars() function, this
way you don't have to hard code the "maximum".
Mick This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matt |
last post by:
Simple vbscript,html page loading into access.
Input pg posting to Confirm pg, then sending to access.
when using;
<textarea name="name" tabindex="15">
</textarea>
as an input renders tab spaces automatically.
|
by: Augustus |
last post by:
Hiya,
I have a form with a <textarea></textarea> to receive user input.
This input is then stored in a database and sent by fax...
I need to be able to remove the carriage returns (enter key... vbcrlf...)
from the input so that somebody doesn't do something like fill the textarea
with 100s of keypresses of the enter key and end up spitting out tonnes of
blank pages on the fax machine
|
by: Dennis Allen |
last post by:
Hi. I hope someone here can help. I'm webmaster for a local astronomy
club. Just went over our web site. Have validated every htm file on the
site except:
http://validator.w3.org/check?uri=http://www.stargazing.net/mas/COMET.htm
In the <textarea> of this page I have Javascript code. I can't figure out
how to present this code and still be w3c valid. Any advice would be
appreciated...Dennis
|
by: Bart Van der Donck |
last post by:
Hello,
I have a dynamic page of which I don't know how many forms will be on
it, neither which and how many elements will be in each form.
I use the following java script to disable all elements from all
forms:
var numberForms = document.forms.length;
var formIndex;
|
by: Jonathan Taub |
last post by:
This may seem a stupid question.
I've got a <textarea> element:
....
<td>
List of items:
<textarea>
1. Apple
2. Orange
3. Box
| |
by: Les Paul |
last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's
just like a Wiki page, but my own very simple version. It's a page full
of plain old HTML content, and then at the bottom, there's an "Edit"
link. So the page itself looks something like this:
<HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY>
<!-- TEXT STARTS HERE -->
<H1>Hello World!</H1>
<P>More stuff here...</P>
|
by: Jarek Mielcarek |
last post by:
hi all,
in xml file I have some fields which are source for <textarea> element.
I'd like to transform this file using xslt and set the rows property of
<textarea> depend of lines in some source field.
How to do this?
regards
jaro
|
by: ASP Yaboh |
last post by:
I have an ArrayList of data gathered from a database. I want to create a web
page from this data by creating a <table>, each cell in each row displays the
appropriate data. One of those cells in each row needs a <textarea> control.
The background supporting classes are completed, the only task left now is
to create the web page. I am at a loss on how to create the table in the page
populated by the data. Previously, I would have just...
|
by: FunkHouse9 |
last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to replace spaces with . The <br> part works well enough, but I keep getting "%20" instead of " " for the spaces.
I understand that escape() changes " " to "%20", but I would think the ConvertSpaces function below would change the %20 to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |