Hi there
Can somebody please help me. I’ve searched the net and read through3 javascript books and
I’m still not sure how to do it. what I want to do is have a comma separated text file in
the following format:
Desc, File
Bobs House, Bob.txt
Johns House, John.txt
Bills House, Bill.txt
I want to load this text file into a layer on a webpage and just be able to see the Desc and
to be able to click on it as a link and it will open the File that it matches. For Example
I click on Bobs House and the contents in Bob.txt are displayed in a table next to the layer
or another layer. the reason I want to do this is to make the site easy to update. All you
have to do is add another entry in the file and it will open another text file when you
click on it.
I really need help.
Thanks
Shane
[CODE]
Desc, File
Bobs House, Bob.txt
Johns House, John.txt
Bills House, Bill.txt
[/CODE]
[CODE]
// MenuLink.js
// "Desc, File",
MenuLink = new Array (
"Bobs House, Bob.txt",
"Johns House, John.txt",
"Bills House, Bill.txt"
);
// NOTE: No comma after last entry
[/CODE]
[code=php]var h = "<select onclick='showLink(this)'>";
for (var i=0; i<MenuLink.length; i++) {
var s = MenuLink[i].split(", ");
h += "<option value=' + s[1] + "'>" + s[0] + "</option>";
}
h += "</select>";
s = document.createElement("div");
d.innerHTML = h;
h = document.getElementById('myForm');
h.appendChild(s.firstChild);[/code]
and then write the function showLink(f) (the form) which will be called when the user picks and item. for (var i=0; i < MenuLink.length; i++){
s = MenuLink[i].split(", ");
h += "<a href='#' onclick='showText(" + i + ")'>" + s[0] + "</a><br>";
}
document.getElementById("test").innerHTML = h;
[code=php]function showLink(f) {
.
.
// url = the url to load
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.statusText == 'OK') {
document.getElementById('loadedText').innerHTML = xmlhttp.responseXML.body.innerHTML;
}
};
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}[/code]
You'll have to find out how to make it work in IE yourself. A search for 'xmlhttp activeX' should get you there.[CODE]<html>
<head>
<script type="text/javascript">
var lineItem = "";
var IE = true;
if (navigator.appName != "Microsoft Internet Explorer"){IE = false}
function displayIt(){
var narrative = window.frames['container'].document.body.lastChild.lastChild.data;
document.getElementById('info').value = narrative;
}
function getData(nFile){
window.frames['container'].location.href = nFile;
setTimeout("displayIt()",1000);
}
function fillSelect(nItems){
var nList = document.getElementById('names');
nList.options.length = 1;
for (each in nItems)
{
var nOption = document.createElement('option');
var isData = document.createTextNode(nItems[each]);
nOption.setAttribute('value',nItems[each]+'.txt');
nOption.appendChild(isData);
nList.appendChild(nOption);
}
nList.selectedIndex = 0;
}
function init(){
if (IE)
{
lineItem = window.frames['container'].document.body.lastChild.lastChild.data;
lineItem = lineItem.replace(/[rn]/g,"|").replace(/||/g,"|").replace(/|$/,"").split(/|/);
fillSelect(lineItem);
}
else {alert('This page is best viewed with Internet Explorer')}
}
onload=init;
</script>
</head>
<body>
<iframe name='container' src='nameList.txt' style='display:none'>
</iframe>
<textarea cols='30' rows='10' id='info' readonly>
</textarea>
<br>
<select id='names' onchange="getData(this.value)">
<option value=""> Make a Selection </option>
</select>
</body>
</html>
[/CODE]
[CODE]Bob
Bill
John
Mack
Buddy
William[/CODE]
[CODE]<html>
<head>
<script type="text/javascript">
var lineItem = "";
var IE = true;
if (navigator.appName != "Microsoft Internet Explorer"){IE = false}
function displayIt(){
var narrative = window.frames['container'].document.body.lastChild.lastChild.data;
document.getElementById('info').value = narrative;
}
function getData(nFile){
window.frames['container'].location.href = nFile;
setTimeout("displayIt()",1000);
}
function fillSelect(nItems){
var nContainer = document.getElementById('linkList');
for (each in nItems)
{
var nLink = document.createElement('a');
var isText = document.createTextNode(nItems[each]);
nLink.setAttribute('href',nItems[each]+'.txt');
nLink.onclick = function(){getData(this.href);return false;}
nLink.appendChild(isText);
nContainer.appendChild(nLink);
nContainer.appendChild(document.createElement('br'));
}
}
function init(){
if (IE)
{
lineItem = window.frames['container'].document.body.lastChild.lastChild.data;
lineItem = lineItem.replace(/[rn]/g,"|").replace(/||/g,"|").replace(/|$/,"").split(/|/);
fillSelect(lineItem);
}
else {alert('This page is best viewed with Internet Explorer')}
}
onload=init;
</script>
</head>
<body>
<iframe name='container' src='nameList.txt' style='display:none'>
</iframe>
<textarea cols='30' rows='10' id='info' readonly>
</textarea>
<br>
<div id='linkList'></div>
</body>
</html>
[/CODE]
var narrative = window.frames['container'].document.body.lastChild.lastChild.data;
var disText = document.createTextNode(narrative);
document.getElementById('info').appendChild(disText);
}
[CODE]<html>
<head>
<script type="text/javascript">
var lineItem = "";
var IE = true;
if (navigator.appName != "Microsoft Internet Explorer"){IE = false}
function displayIt(){
var narrative = window.frames['container'].document.body.lastChild.lastChild.data;
document.getElementById('info').innerHTML = narrative;
}
function getData(nFile){
window.frames['container'].location.href = nFile;
setTimeout("displayIt()",1000);
}
function fillSelect(nItems){
var nContainer = document.getElementById('linkList');
for (each in nItems)
{
var nLink = document.createElement('a');
var isText = document.createTextNode(nItems[each]);
nLink.setAttribute('href',nItems[each]+'.txt');
nLink.onclick = function(){getData(this.href);return false;}
nLink.appendChild(isText);
nContainer.appendChild(nLink);
nContainer.appendChild(document.createElement('br'));
}
}
function init(){
if (IE)
{
lineItem = window.frames['container'].document.body.lastChild.lastChild.data;
lineItem = lineItem.replace(/[rn]/g,"|").replace(/||/g,"|").replace(/|$/,"").split(/|/);
fillSelect(lineItem);
}
else {alert('This page is best viewed with Internet Explorer')}
}
onload=init;
</script>
</head>
<body>
<iframe name='container' src='nameList.txt' style='display:none'>
</iframe>
<div id='info' style='border:1px solid black;height:100px;width:150px;font-size:12pt;padding:3px;overflow:auto;'></div>
<br>
<div id='linkList' style='border:1px solid black;background-color:#f0fff0;width:100px;height:75px;overflow:auto;padding:5px;margin:5px;font-size:12pt'></div>
</body>
</html>
[/CODE]
[CODE]function getData(nFile){
window.frames['container'].location.href = nFile;
[B]document.getElementById('info').scrollTop = 0;[/B]
setTimeout("displayIt()",1000);
}
[/CODE]
[CODE]function getData(nFile){
window.frames['container'].location.href = nFile;
[B]document.getElementById('info').innerHTML = "";[/B]
setTimeout("displayIt()",1000);
}
[/CODE]
0.1.9 — BETA 5.28