473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

count chars?

roN
Hey,

I got following:
[html]
<form name="Formular" method="post" onSubmit="return chkFormular()"
action="mail.php" enctype="text/plain">
....
....
....
<td align="right" valign="top" class="text"><font
color='red'>*</font>Comments/Questions:<br>
<input name="input" size="1"
style="border-width:0;background-color:#FFFFFF"
onfocus="if(this.blur)this.blur()">
chars left</td>
<td class="text"> <textarea name="comments"
onkeyup="count(event)" rows="8" cols="40" class="flat"></textarea>
</td>
[/html]
[js]
<script language="JavaScript">
var max = 255;

document.Formular.input1.value = max;
document.Formular.comments.focus();

function count(e) {
if (!e.which) keyCode = event.keyCode; // ie5+ op5+
else keyCode = e.which; // nn6+

if (document.Formular.comments.value.length<max+1)
document.Formular.input1.value =
max-document.Formular.comments.value.length;
else {
document.Formular.comments.value =
document.Formular.comments.value.substring(0,max);
document.Formular.input1.value = 0;
}
}
</script>
[/js]
That's supposed to display how many chars are left besides the textarea,
decreasing from 255. But it doesn't display anything, why not? Thank you
guys!
--
chEErs roN

I'm root, I'm allowed to do this! ;)
keep on rockin'
Feb 15 '06 #1
2 1771
roN wrote:
Hey,

I got following:
[html]
<form name="Formular" method="post" onSubmit="return chkFormular()"
action="mail.php" enctype="text/plain">
...
...
...
<td align="right" valign="top" class="text"><font
color='red'>*</font>Comments/Questions:<br>
<input name="input" size="1"
style="border-width:0;background-color:#FFFFFF"
onfocus="if(this.blur)this.blur()">
chars left</td>
<td class="text"> <textarea name="comments"
onkeyup="count(event)" rows="8" cols="40" class="flat"></textarea>
</td>
[/html]
[js]
<script language="JavaScript">
var max = 255;

document.Formular.input1.value = max;
The script console told me that document.Formular.input1 has no
properties. That is because your input has a name of 'input'. Change
it to input1 and it 'works'.

document.Formular.comments.focus();

function count(e) {
if (!e.which) keyCode = event.keyCode; // ie5+ op5+
else keyCode = e.which; // nn6+

if (document.Formular.comments.value.length<max+1)
document.Formular.input1.value =
max-document.Formular.comments.value.length;
else {
document.Formular.comments.value =
document.Formular.comments.value.substring(0,max);
document.Formular.input1.value = 0;
}


That appears to be an extremely lengthy way to go about things. Why not
change the call to:

<textarea name="comments" onkeyup="count(this)" ... >
And the function to:

function count(el)
{
document.Formular.input1.value = max - el.value.length;
}

[...]
--
Rob
Feb 16 '06 #2
RobG wrote:
That appears to be an extremely lengthy way to go about things.
Why not change the call to:

<textarea name="comments" onkeyup="count(this)" ... >
And the function to:

function count(el)
{
document.Formular.input1.value = max - el.value.length;


document.forms['Formular'].elements['input1'].value =
max - el.value.length;

is (almost) standards compliant (apart from `document') and backwards
compatible.
PointedEars
Feb 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: grocery_stocker | last post by:
#include <iostream> //for cin and cout #include <iomanip> // for setw() #include <string> // for strlen() strcmp() strrev() #include <fstream> //ifstream and ofstream: file (input & output)...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
8
by: Joe Reynolds | last post by:
say i have a string that is "hello this is my string and i like it very much" and i want to insert a newline at every 20th character, how could i go about doing this?
0
by: euniceno1 | last post by:
the problem is to count the letters and sequence from a file. the fist thing of my code is to read file and in the main function i create is to count the characters and sequence by using 2 dimension...
3
stealwings
by: stealwings | last post by:
Hello everyone; I have this code to count the number of chars of every getline, now I was wonder if someone could tell me how can I get the sum of all the lines, I have tried for loop but since...
17
by: Umesh | last post by:
Please try to do it while I try myself!
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
3
by: jcor | last post by:
Hi, I'd like to know how I cancount characters user inputs while they input it. Imagine something like this: See this example how this could work: input your title (2 chars): My input your...
5
by: gflor16 | last post by:
Problem: I have this code to run a word counter. But I have a problem when I hit the enter key, it doesn't give me any output of how many chars or words. ''' <summary> ''' Returns Word...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.