Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

53 of 65 people (82%) answered Yes
Recently 4 of 10 people (40%) answered Yes


how to call a html file in textarea

Apr 6th, 2008 18:52
ha mo, suresh kc, Colin Fraser, Sumegha,

<script language=Javascript>
function fileReader() {
//readFile is the name of the applet in the document
//getContents is the applet method that returns the contents of the file
//passed as the parameter to the applet via param tag
//see the applet code below
//you will have to compile the applet code first in order to
//be able to use this
	var contents = document.readFile.getContents();
	document.myform.txtarea.value = contents;
<body onload=fileReader();>
<applet name=readFile code=ReadFile.class width=1 height=1>
<param name=file value="">
<form name=myform>
<textarea name=txtarea cols=80 rows=20 NOWRAP>
//code for FileReader Applet
import java.applet.*;
import java.awt.*;
public class ReadFile extends Applet {
	String contents="";
	public void init() {
		try {
		BufferedReader br = new BufferedReader 
				(new FileReader(getParameter("file")));
		String s="";
		while((s = br.readLine()) != null) {
			contents += s+"\n";
		} catch (FileNotFoundException fnfe) {
			contents = fnfe.getMessage();
		catch(IOException ioe) {
			contents = ioe.getMessage();
	public String getContents () {
		return contents;