Jump to content
  • Advertisement
Sign in to follow this  
GameMasterXL

[web] Counting textarea lines?

This topic is 4677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Using javascript, you could just go through all the characters and see if it is a line break:

function count()
{
var str = document.getElementById("theTextArea").value;
var num = 0;

for (i = 0; i < str.length; i++)
{
if (str.charAt(i) == '\n')
num++;
}

return num;
}

Above code could be optimized a little, it's just to give you an idea.

Share this post


Link to post
Share on other sites
Ah that did the trick thanku so so much for the help. One thing do you know how i can get it to make a new number on a new line when i just press enter?

my code here:

function count()
{
var str = document.getElementById("SyntaxView").value;
var num = 0;

for (i = 0; i < str.length; i++)
{
if (str.charAt(i) == '\n')
num++;
}
document.getElementById('lines').innerHTML=document.getElementById('lines').innerHTML+num+"\n";
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!