/    Sign up×
Community /Pin to ProfileBookmark

Textarea line counter

Hy.

I would need a JavaScript that counts how many lines are written in an HTML textarea.

Thanks for any responses.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvJun 21.2004 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript">
function getLineAmount(ta)
{
return ta.value.split(/n/).length;
}
</script>
</head>
<body>
<form action="#">
<fieldset>
<legend>Textarea Line Counter</legend>
<textarea id="foo" rows="10" cols="59"></textarea>
<input type="button" value="How many lines?" onclick="alert(getLineAmount(document.getElementById('foo')));">
</fieldset>
</form>
</body>
</html>
Copy linkTweet thisAlerts:
@Phantom14authorJun 21.2004 — Thanks
×

Success!

Help @Phantom14 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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