[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. :-(