Click to See Complete Forum and Search --> : Loading txt from .js in iframe on click
how would i load text using a href in the same page inside an iframe using an externall .js...i need multiple entries in the .js ...here is an example of the .js..ne1 know a solution?
mytxt.js
ITEMS = [
{
'content1' : 'my text here',
'content2' : 'my text here',
'content3' : 'my text here',
'content4' : 'my text here',
'content5' : 'my text here',
}
]
javaNoobie
10-06-2004, 09:28 PM
I'm not sure what you want. Here's an example on how to reference it
<script type="text/JavaScript">
ITEMS = {
content1 : 'my text1 here',
content2 : 'my text2 here',
content3 : 'my text3 here',
content4 : 'my text4 here',
content5 : 'my text5 here'
}
alert(ITEMS['content1']);
</script>
Warren86
10-07-2004, 06:08 AM
ilya:
Use and object in the .js file, and put the text into fields of the object. Like this:
------------ Data.js --------------
Item = new Object
Item.A = "This is Item A"
Item.B = "This is Item B"
Item.C = "This is Item C"
Item.D = "This is Item D"
-------------- Main document -----------
<HTML>
<Head>
<Script Language=JavaScript Src='Data.js'></Script>
<Script Language=JavaScript>
// Other Script goes here
</Script>
</Head>
<Body>
<Div id='A'><Script> A.innerText = Item.A </Script></Div>
<Div id='B'><Script> B.innerText = Item.B </Script></Div>
<Div id='C'><Script> C.innerText = Item.C </Script></Div>
<Div id='D'><Script> D.innerText = Item.D </Script></Div>
</Body>
</HTML>
You canont use numbers in the name of the object or in the name of any of its fields.
Warren86
10-07-2004, 07:08 AM
Ilya:
I didn't notice that you need to do this with an IFRAME. Try the following, with the previously posted .js file.
<HTML>
<Head>
<Script Language=JavaScript Src='Data.js'></Script>
<Script Language=JavaScript>
function xferText(curr){
isText = Item[curr]+"<br>";
txtFrame.document.write(isText);
}
</Script>
</Head>
<Body>
<IFRAME
Name = 'txtFrame'
Width = 200
Heigth = 50>
</IFRAME>
<br><br>
<input type=button value="Item A Text" onClick="xferText('A')">
<br>
<input type=button value="Item B Text" onClick="xferText('B')">
<br>
<input type=button value="Item C Text" onClick="xferText('C')">
<br>
<input type=button value="Item D Text" onClick="xferText('D')">
</Body>
</HTML>
i wanted the text to load when i click the url to it..
|---------|
|link 1 |
|---------|
|---------| Text appears here in an iframe or div
|link 2 | it dont matter..this is so i dont
|---------| have to make diff pages for lots of diff
categories of text..its like a database.
|---------|
|link 3 |
|---------|
Warren86
10-07-2004, 02:44 PM
Like this?
-------- I see it happened again. This system changes javascript to java script. In the code below, it must be javascript. Make the necessary changes.
---------
<HTML>
<Head>
<Script Language=JavaScript Src='Data.js'></Script>
<Script Language=JavaScript>
function xferText(curr){
isText.innerText = Item[curr];
}
</Script>
</Head>
<Body>
<Div id='isText'></Div><br>
<a href=javaScript:xferText('A')> First Link </a><br>
<a href=javaScript:xferText('B')> Second Link </a><br>
<a href=javaScript:xferText('C')> Third Link </a><br>
<a href=javaScript:xferText('D')> Fourth Link </a>
</Body>
</HTML>