Menu
I have a readonly textarea where I want the text to be loaded from an external file like a txt file (but i was reliably informed that I couldnt use .txt but could get away with a .js file)
I was just wondering if anyone knows of a way to load the external file into the textarea.
Thanks for reading
Rob
Update:- an effect simmilar to this but using javaScript not flash
[URL=http://visualintensity.com/flash/mx2004/textarea-load/]working example
[CODE]----your HTML file----
<html>
<head>
<script>
function loadContent(){
document.forms[0].myText.value = content;
}
</script>[COLOR=red]
<script language="JavaScript" src="content.js" type="text/javascript"></script>[/COLOR]
</head>
<body>
<form>
<textarea name="myText" cols="40" rows="10"></textarea>
</form>
<span onClick="loadContent()">HELLO</span>
</body>
</html>
##########################################
----content.js----
var content = 'Whatever you want to go into the text area. Use the r symbol for a line break in the text area. So if I write, HellorMy name is Jesse, it will appear: Hello (next line) My name is Jesse'[/CODE]
Hope this helps. The key is the red code above - the link to the js file. The function at the top of the HTML file sets the value of the text area to the variable from your js file. This would almost be easier if you just created that variable in the head of your HTML doc, but it's not my project. Good luck.[CODE]<html>
<head>
<script language="javascript">
function loadContent(){
document.forms[0].myText.value = content;
}
</script>
<script language="JavaScript" src="content.js" type="text/javascript"></script>
</head>
<body>
<form>
<textarea readonly name="myText" cols="40" rows="10"></textarea>
</form>[COLOr=red]
<script>
loadContent();
</script>[/COLOR]
</body>
</html>[/CODE]
You can't call the function onLoad because the text area does not exist yet because it has not yet been created. So you must create the text area, then call it - see my code?[code=php]<html>
<head>
<script type="text/javascript">
<!--
function loadContent(){
document.write(content);
}
//-->
</script>
<script src="content.js" type="text/javascript"></script>
</head>
<body>
1+1=
<script type="text/javascript">
<!--
loadContent()
//-->
</script>
</body>
</html>[/code]
or[code=php]<html>
<head>
<script src="content.js" type="text/javascript"></script>
</head>
<body>
1+1=
<script type="text/javascript">
<!--
document.write(content);
//-->
</script>
</body>
</html>[/code]
content.js:[code=php]var content="<span style='background-color:#808080'>2</span>";[/code]
Keep a note that you cannot use the onLoad event handler with this method. After the page loads, any call for document.write() will clear all the html and write whatever is in the document.write(). So you have to call document.write() [i]while[/i] the page is loading.[code=php]<html>
<head>
<title>title</title>
<script language="javascript">
function loadContent(){
document.forms[0].myText.value = content;
}
</script>
<script language="JavaScript" src="content.js" type="text/javascript"></script>
</head>
<body onLoad="loadContent()" bgcolor="#000000" text="#FFFFFF"><div align="center"><img src="background.gif"></div>
<form><textarea readonly name="myText" wrap="hard" id="text" style="position:absolute; top::228px; left::187px; overflow: scroll; width: 651px; height:: 316px; background:background-color:#000000; color:#ffffff; left: 184px; top: 235px; height: 325px; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;"></textarea></form>
</body>
</html>[/code]
[code=php]var = "http://www.webdeveloper.com"[/code]
[code=php]<html>
<head>
<script src="content.js" type="text/javascript"></script>
</head>
<body>
<div style="background-image:url('background.gif')">
<script type="text/javascript">
<!--
document.write(content);
//-->
</script>
</div>
</body>
</html>[/code]
[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body bgcolor="#000000" text="#FFFFFF"><div align="center" style="position:absolute; top:0px; left:0px;"><img src="../imgMaps/bike2.jpg"></div>
<div style="position:absolute; top:15px; left:15px; overflow: none; width: 300px; height: 300px; border: 1px none #000000;background-color:#ffffff"><iframe src="microbyte_content.htm" id="myText" style="width: 100%; height: 100%; border: 1px none #000000;"></iframe></div>
</body>
</html>[/code]
And the microbyte_content.htm:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
.maintext {
color: #237FB3;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
.subtext {
color: #000000;
font-family: arial;
font-size: 12px;
font-weight: normal;
}
-->
</style>
</head>
<body>
<div class="maintext">Textarea with External Text and CSS</div>
<br>
<div class="subtext">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis auctor. Pellentesque interdum lectus nec justo. Praesent at tortor in leo sagittis commodo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti. Integer sagittis, dolor eget sagittis lacinia, dui diam venenatis nisl, sit amet elementum mi felis eu metus. Pellentesque bibendum tempor odio. Fusce malesuada laoreet ante. Praesent placerat ante eget erat. In elementum. Vestibulum vel dui. Morbi id mauris. In non massa.</div>
<br>
<div class="subtext">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis auctor. Pellentesque interdum lectus nec justo. Praesent at tortor in leo sagittis commodo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti. Integer sagittis, dolor eget sagittis lacinia, dui diam venenatis nisl, sit amet elementum mi felis eu metus. Pellentesque bibendum tempor odio. Fusce malesuada laoreet ante. Praesent placerat ante eget erat. In elementum. Vestibulum vel dui. Morbi id mauris. In non massa.</div>
</body>
</html>[/code]
Cheers - Pit0.1.9 — BETA 6.2