Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probably pretty simple

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
0
0
US
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
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?
 
Hi,

Your script works almost fine for me, with the exception that "responsetext" should be "responseText" -> [blue](output.value = httpRequest.responseText;)[/blue]

When you say it does not work at all, do you recieve any javascript errors, or is nothing ever displayed in the textarea etc?

Chris
 
Are you running this through a web server ( or a local file protocol (file://). If the latter, try the former.

Also see forum1600 for more on AJAX.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Zhris'

tried your output value remedy but no response

and also for Billy Ray

what I mean by no response is that the text box displays no text (doesnt load) and just displays the error message
 
I'd assumed when you said 'error message' that it was actually a JS error message rather than just your own string.

Perhaps you can alert the status code and see what it is coming back as, as it's clearly not 200...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Here's my error: <option value="003,txt">Contractor 3</option>

notice the comma instead of the dot.... oi, its the little things
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top