/    Sign up×
Community /Pin to ProfileBookmark

Javascript- Textbox counter in increments of 100

hello,
I have a textbox in my .net page, and totally new to java script.

How do i get a script that will count the data being written in the text box to show increments of 100 and write the value to the bottom of the textbox.

e.g. When u get to 100, at the bottom it says “1st hundred”

… and to 200 it writes “2nd hundred”

UP to 500 ???

Please help
thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERFeb 19.2011 — hello,

I have a textbox in my .net page, and totally new to java script.

How do i get a script that will count the data being written in the text box to show increments of 100 and write the value to the bottom of the textbox.

e.g. When u get to 100, at the bottom it says "1st hundred"

... and to 200 it writes "2nd hundred"

UP to 500 ???

Please help

thanks[/QUOTE]


What data are you trying to count?

Characters or lines or something else?

And data is in a 'textbox' or a 'textarea'?

Need clarification to continue.
Copy linkTweet thisAlerts:
@omerhassanFeb 19.2011 — [code=html]
<textarea onKeyUp="keyUp(this);"></textarea>
<input type="text" disabled id="message"/>

<script type="text/javascript">
function keyUp(textarea)
{
var length = textarea.value.length;

if (length % 100 == 0)
document.getElementById('message').value = length + " reached.";
}
</script>
[/code]
Copy linkTweet thisAlerts:
@tirnaFeb 20.2011 — I'm assuming you want to count characters.

You can use a textbox or textarea.
[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<title></title>
<script type="text/javascript">
var maxChars = 500;
function countChars(str){
txtInpObj.value = (str.length <= maxChars)? str : str.substring(0,maxChars);
numCharsDivObj.innerHTML = (str.length >= 100)? numCharsDivObj.innerHTML = 'Number of hundred: '+Math.floor(str.length/100.0) : '';
}
window.onload=function(){
txtInpObj = document.getElementById('txtInp');
txtInpObj.onkeyup=function(){
countChars(this.value);
}
numCharsDivObj = document.getElementById('numCharsDiv');
}
</script>
</head>
<body>
<div>
<textarea id="txtInp" cols="20" rows="5"></textarea>
<div id="numCharsDiv"></div>
</div>
</body>
</html>
[/CODE]
×

Success!

Help @mary_itohan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...