473,473 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Display of line numbers

14 New Member
Hi all,
I want to display the line numbers for the text which resides inside the text field.How can i do this?Please help me.
Dec 18 '07 #1
2 2566
gits
5,390 Recognized Expert Moderator Expert
please post what you have so far ... so that we might have an example to work with ...

kind regards
Dec 18 '07 #2
amulyab
14 New Member
[HTML]<HTML>
<HEAD>
<SCRIPT>
function readFile (fileName) {
alert("aaa");
if (document.layers && navigator.javaEnabled()) {

netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead');
var bfr = new java.io.BufferedReader(new
java.io.FileReader(fileName));
var line;
var content = '';
while ((line = bfr.readLine()) != null)
content += line + java.lang.System.getProperty('line.separator');
return content;
}
else if (document.all) {
alert("bbb");
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fs = fso.OpenTextFile(fileName);
var result = fs.ReadAll();
return result;
}
}
</SCRIPT>



</HEAD>
<BODY>
<FORM NAME="formName">
<INPUT TYPE="file" NAME="fileName">
<INPUT TYPE="button" VALUE="show"
ONCLICK="this.form.fileContent.value =
readFile(this.form.fileName.value)"
>
<BR>
<TEXTAREA NAME="fileContent" ROWS="20" COLS="80" WRAP="on"></TEXTAREA>
</FORM>
</BODY>
</HTML>[/HTML]

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>selecting a line in a textarea in Mozilla</title>
<script type="text/javascript">
function selectLine (textarea, text1,text2) {
alert("aaa");
var text = textarea.value;
alert(text);
lineNumber1 = Number(text1);
alert(Number(text1));
lineNumber2 = Number(text2);
alert(Number(text2));
var linePattern = /.*(\r\n|\r|\n)/g;
alert(linePattern);
linePattern.lastIndex = 0;
var lineStart = 0;
var lineEnd = 0;
var lineMatch;
var lineFound = 0;
var found = false;
while ((lineMatch = linePattern.exec(text))) {

lineFound++;
lineStart = lineMatch.index;

lineEnd = lineStart + lineMatch[0].length;
alert(lineEnd);
if (lineFound == lineNumber2 ) {
found = true;
break;
}
}
if (found) {
if (textarea.setSelectionRange) {
textarea.scrollTop = Math.floor(textarea.scrollHeight /
countLines(text) * (lineNumber2 - 1));
textarea.setSelectionRange(lineStart, lineEnd);
}
}
}

function countLines (text) {
var linePattern = /.*(\r\n|\r|\n)/g;
linePattern.lastIndex = 0;
var lineCount = 0;
var match, index, matchText;
while ((match = linePattern.exec(text))) {
lineCount++;
index = match.index;
matchText = match[0];
}
if (index + matchText.length < text.length) {
lineCount++;
}
return lineCount;
}
</script>
</head>
<body>
<form action="">
<p>
<label>
example textarea:
<br>
<textarea name="textareaName" rows="10" cols="80">
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13
Line 14
Line 15
</textarea>
</label>
</p>
<p>
<label>line number:</label>
<input type="text" name="text1" id="text1">
<input type="text" name="text2" id="text2">
<input type="button"
value="select line"
onclick="selectLine(this.form.elements.textareaNam e,this.form.elements.text1.value,this.form.element s.text2.value);">
</p>
</form>
</body>
</html>
[/HTML]
1. In this code the 1st javascript reads the uploaded file and displays the contents in the text area,but this works only in IE,i want the same function to be worked in the Mozilla Firefox and also along with the contents it should display the line numbers.

2. In my second javascript i need to change the code like,if i select the start and end line numbers which are entered in 2 text boxes, it should highlight the contents.
Please please help me.Its very urgent. :-(
Dec 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: drew | last post by:
I am reading my textbook and doing the code examples in MS Visual C++ 6.0 for my next class beginning Jan 05. The textbook examples show line numbers. How do I get line numbers to show as I type in...
2
by: kak3012 | last post by:
Hi, I have a text file I will read it and write out binary. The file includes 256 coloums. I use while (infile.good()) { infile.getline (buffer,2200);
5
by: BlueFox | last post by:
Hi : When i display the DataBase in System.Windows.Forms. DataGrid ,i want to display the line number of ever line .How can i do it ? Any help may be Good .
2
by: rammohan | last post by:
i want to implement an option similar to line numbers option in c# editor. how can i display line numbers on left side in text box.how can i know the present cursor location with respect to...
4
by: J L | last post by:
Are there any free add-ins for VB.Net that will add and remove line numbers from the source code? TIA John
8
by: nineteen | last post by:
for example: 16/5: 3 -------- 5)16 15 -------- 1 the user input the dividend and divisor,the program should display the upright formula like the example. and , the program must use recursive...
4
by: Samantha | last post by:
I am new to Python and am attempting to write a routine that will display a five game selection for a power ball drawing. I think I have the random drawing set to work ok, but I want to have the...
4
by: Darin | last post by:
I have a public class that I use to read columns out of a SQL database. In the try, catch, loop I want to display the error, and in the error I want to display the calling routine (and helpfully...
1
by: =?Utf-8?B?RG90TmV0RGV2?= | last post by:
Hi, I don't know what I changed, but now when I debug an application I don't see the exact line number in the stack trace. I do see the functions but not the line numbers. Some times its very...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.