Hi All,
this is probably straight foward to some of you, but I'm either going brain-dead or am just loopy.
I have a simple option select menu
and I'm trying to populate the textarea with the contents of external .txt files. I'm using this script:
but it appears to not work at all - i've been around and about the web - but mostly i find either database or asp types or populate the menu - this is not what I'm after.
All I'm trying to do is have the contents of each txt file display in the textarea, the txt file contains a list of contractors and phone numbers for a given area.
Does this seem crazy?
this is probably straight foward to some of you, but I'm either going brain-dead or am just loopy.
I have a simple option select menu
Code:
<select id="contractor" onchange="put_file_contents(document.getElementById('contractor').value,document.getElementById('chosen_link'));">
<option>Find a Contractor</option>
<option value="001.txt">Contractor 1</option>
<option value="002.txt">Contractor 2</option>
<option value="003,txt">Contractor 3</option>
</select><p>
<textarea name="chosen_link" id="chosen_link"cols="" rows=""></textarea>
and I'm trying to populate the textarea with the contents of external .txt files. I'm using this script:
Code:
function put_file_contents(url, output){
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
output.value = httpRequest.responsetext;
}
else {
output.value = "No Data Available";
}
}
else {
output.value = "Loading...";
}
};
httpRequest.open('GET', url, true);
httpRequest.send('');
}
but it appears to not work at all - i've been around and about the web - but mostly i find either database or asp types or populate the menu - this is not what I'm after.
All I'm trying to do is have the contents of each txt file display in the textarea, the txt file contains a list of contractors and phone numbers for a given area.
Does this seem crazy?