This is in the head: - <script language="javascript" type="text/javascript">
-
function limitText(limitField, limitCount, limitNum) {
-
if (limitField.value.length > limitNum) {
-
limitField.value = limitField.value.substring(0, limitNum);
-
} else {
-
limitCount.value = limitNum - limitField.value.length;
-
}
-
}
-
</script>
This is the form: - <form name="myform">
-
<textarea name="limitedtextarea" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,100);"
-
onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,100);">
-
</textarea><br>
-
<font size="1">(Maximum characters: 100)<br>
-
You have <input readonly type="text" name="countdown" size="3" value="100"> characters left.</font>
-
</form>
The issue is that the textarea where I plan to use this script doesn't live inside a form tag. And, as you can see, one of the arguments being passed in is the "this.form" .
I need the form info for the ELSE of the function. Any suggestions? Adding a form tag is not recommended for me at the moment.
THANKS!
7 2153 hsriat 1,654
Recognized Expert Top Contributor
Instead of making the referance as this.form.limit edtextarea, you can just write this, because you are inside that textarea tag (limitedtextarea).
And for the countdown text, you can use document.getEle mentById('count down') (for this you need to add id="countdown" to the countdown input tag)
Regards,
Harpreet
A textarea should always be inside a <form> tag.
hsriat 1,654
Recognized Expert Top Contributor
A textarea should always be inside a <form> tag.
Not a mandatory requirement!
Yeah, I knew it wasn't mandatory. In the way our application is created, there are specific reasons why they placed this field outside a form tag.
Anyways. I made the suggested changes. My field looks like this: - <textarea name="creditNotes" onKeyDown="limitText(this.creditNotes,document.getElementById('countdown'),100);" onKeyUp="limitText(this.creditNotes,document.getElementById('countdown'),100);" id="creditNotes" cols="40" rows="6" style="width:324px; height:82px;"></textarea></div>
-
<font size="1">(Maximum characters: 100)<br>
-
You have <input readonly type="text" id="countdown" name="countdown" size="3" value="100"> characters left.</font>
The script looks the same as before. However, I an error that states that limitField has no properties. "limitField " should contain the value of the "creditNote s" field.
hsriat 1,654
Recognized Expert Top Contributor
Do this change: - <textarea name="creditNotes" onKeyDown="limitText(this, document.getElementById('countdown'), 100);" onKeyUp="limitText(this, document.getElementById('countdown'), 100);" id="creditNotes" cols="40" rows="6" style="width:324px; height:82px;"></textarea>
-
-
</div>
-
-
<font size="1">(Maximum characters: 100)<br>
-
You have <input readonly type="text" id="countdown" name="countdown" size="3" value="100"> characters left.</font>
It worked! Thank you very very much Harpreet! ^_^
hsriat 1,654
Recognized Expert Top Contributor
You are welcome. :)
You know when you write this inside a tag, you refer to that particular tag. So there was no need of this.creditNote s. That would return nothing.
Regards,
Harpreet
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jay |
last post by:
I have an HTML form with a textarea. When passing large
amount of data in the textarea, the Processing asp pages
catch an error message as follows:
Error Type:
(0x80020009)
Exception occurred.
The error is generated once the trim or length or replace
function is called on the field when long text is passed
in the textarea.
|
by: wing |
last post by:
Hi all,
I find a JavaScript that limits the field length in a textarea, but it
is not completed.
The script does not handle the copy and paste case. For example, says
the textarea field length is limited to 5 and a 6-character length
text is pasted, no event is triggered. (The script only handles
onKeyPress and onKeyUp)
|
by: yawnmoth |
last post by:
say i have a form where, if a user clicks in it, all the text is
highlighted, and where, if a user clicks on a button outside of the
form, a certain text string is inserted where the cursor in the
textarea is. why is it, then, that when i, immediatly after loading
the page, click in the textarea, highlighting the text, click again in
the middle of the text (effectively unhighlighting everything, as
well), and then click on the button to...
|
by: Jesper Rønn-Jensen |
last post by:
I have a textarea that must be limited to 70 characters. No big deal --
at least so I thought.
* Textarea must not exceed 70 characters
* Exceeding content must be cut off
* Must work on input by keyboard (keypress, keyup events)
* Must work on pasted input from context menu
* Must work on pasted input via CTRL+V and similar
* Must work on pasted input via browsers menu>Edit>Paste
* Must work in Mozilla + IE and coded via W3C standards
|
by: tony wong |
last post by:
i wish to count number of characters in textarea box during typing in and
display it somewhere in html page. so the number will increase during
writing.
is it possible to do it by javascript?
Thanks a lot.
Tony
| |
by: JohnSouth |
last post by:
Hi
In a TextBox I can set a maximum size for the entry.
Is there a way of limiting the number of characters being entered into
a TextArea control?
John South
www.wherecanwego.com
|
by: @sh |
last post by:
Guys,
Working on a function to alert the user to too many characters being entered
into a text area, I've put together this function so far borrowing bits from
resource websites...
function
Ash_LimitMaxTextAreaCharacters(TheMaxCharacters,TheFriendlyFormName) {
if(document.myform.box.value.length > TheMaxCharacters) {
alert('Sorry but '+TheFriendlyFormName+' contains too many characters,
|
by: teser3 |
last post by:
I have the below that limits the textarea input to 500 characters but
cant get the alert message to work. It doesnt show anything. Please
advise.
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
alert("You are trying to enter more
than 500 characters");
} else {
|
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= |
last post by:
I need to emulate the missing "maxlegth" attribute in "textarea" fields
but all my Google searches either lead to obsolete scripts that
overwrite the "value" property (thus losing caret position) or to
complex solutions that work on top of specific frameworks.
Do you have some reference on how to do it? I'd like to make it work in
at least Firefox and IE 6 and 7.
Thank you in advance,
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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...
| |