Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea LineCount help 1

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
hello,
I am new to vbscript and I read a bit about the LineCount thing and was wondering if you can use that command to display the line numbers of a textarea.......

like if I key down with the down arrow, while in the textarea, and I am on the fifth line a textbox or textarea, seperate from the original textarea, would then display the line number....

any scripting example would be great,

I hope this isnt too difficult and any help is much appreciated.

co
 
I am not sure I am following you. Is your desire to have a web page with a text area and to just display the number of lines that get input into a text area box?

It sounds to me like you are looking to have code automatically display the line number, but your script would not be executed until a form submit was done.

I'm not an ASP guru but I believe the above to be correct.
 
You can do this in client-side script. Use the onkeydown event of the TextArea to detect whenever the user types in a character. Your client-side javascript code (don't use VBScript client-side as many browsers don't support it) attached to the event can then examine the text in the TextArea object and calculate the current number of lines.

See this URL for a simple example:

 
Hey,
thats a great link with a good idea, I figured Id do it that way...but what is the syntax which counts and displays the amount of lines...

id actually like it to where I could use the arrow keys and when I key up or down threw the textarea the line number would display in a textbox or whatever....

i would like to have it so, if I click on lets say line 10 then the box would show: ln:0010...

just like in Notepad or what not...

thanks for your help so far, hope you can help me out a little more.

code one
 
You'll need to have a listbox control that contains the line numbers. Initially it will have no line number in it but as the textarea is filled you will add a number every time a complete line has been entered.

You can figure out the number of lines by dividing the length of the text in the textarea by the width of the textarea. So if its width is 50 characters then the number of lines = (lengthoftext / 50) + 1. You may also wish to allow for CR or LF characters producing an extra line.

You will then add another entry to the number listbox if the number of lines exceeds the current number in the list box. You will also have to allow for people deleting lines.

I'm not going to provide any code for this as you need to figure out the details for yourself as this will help you understand fully what you are doing and help you gain useful experience.

Good luck
 
Hey,

I was projecting the idea of line deletion, line breaks and such, and I think this isnt going to be too hard to accomplish, thanks for the hints, I agree learning this on my own would be best, so thanks for the help.

Just wondering, should I generate the numbers or store them in an array?

thanks

Co
 
Hey re read your post a bit better and you suggested a listbox
now are you saying that instead of using a textbox or textarea I should use a select aka list box to display the line values of the textarea I type into?

Geez, that would kinda suck because like you said Id have to add values or limit the textarea, in order to keep it slick, plus that would be ugly to look at, now I could have a list box and hide it and then display the valyue of that in a text box or textarea but still I would have to either keep adding values or limit the textarea, and to me that would be too much of a hassle and or annoyance, although Im sure I could programmicly generate a new value on line break of course but still I'm afraid the code will be shaky and not worth the time spent, purhaps I'll think of a simpiler way to accomplish his, by coding up a line find...

thanks

code one
 
Hey bboffin,

I junked the line find and went back to the intial plan and this is what I got, still needs to look for line breaks, but does the trick, maybe for error purposes I'll add a line find, but for now this is what I got:

Code:
<html>
<head>
<title>line count</title>
<script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot;>

function getTextareaLines(field_ref,field_cols) {
if (!field_ref) return;
field_cols = field_ref.cols ? field_ref.cols : field_cols;
return Math.ceil(field_ref.value.length/field_cols);
}

</script>
</head>
<body>
<form>
<textarea cols=&quot;60&quot; rows=&quot;20&quot; wrap=&quot;soft&quot;
onkeydown=&quot;window.status='Number of lines: 

'+getTextareaLines(this,60)&quot;>
</textarea>
</form>
</body>
</html>

pretty cool huh?

regards

code one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top