Re: Newbie Question - variable name in getElementById() method doesn't seem to work



<spivee@xxxxxxxxx> wrote in message
news:1138660812.559010.118930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Okay, I'm swift as a fork in the road.. Finally found the solution,
> though it seems odd to me... I took the handleResponse(id) out of
> doGetUrl() and changed the sendRequest() function as follows and it
> works.
>
> function sendRequest(url, id) {
> http.open('get', url);
> http.onreadystatechange = function() { handleResponse(id) }
> http.send(null);
> }
>

How about simplifying your code. Watch for word-wrap.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>doGetUrl.htm</title>
<script type="text/javascript">
function createRequestObject() {
var ret = null;
if (window.ActiveXObject) {
try {
ret = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {}
} else if(window.XMLHttpRequest) {
try {
ret = new XMLHttpRequest();
} catch(e) {}
}
return ret;
}
function doGetUrl(id,url) {
var http = createRequestObject();
http.open('get', url, false);
http.send(null);
var response = http.responseText;
if (response.indexOf('|' != -1)) {
var update = response.split('|');
var data = update[0];
document.getElementById(id).innerHTML = data;
}
}
</script>
</head>
<body>
<div id="myTest">myTest</div>
<br><br>
<a href="#" id="myHref" onMouseOver="doGetUrl('myTest','myfile')">change
content</a>
</body>
</html>


And you don't need
id="myHref"
as it's not referenced.

I haven't validated (per w3c) your code; I just made it work.

However, it would be noce to have a sample of what is returned;
apparently it must be a string with "|" in it...


.



Relevant Pages

  • Re: MMX for inverse DCT
    ... I'm interested in MMX/SSE routines for both, ... TsdSampleBlock; var Quant, Wrksp: TsdIntArray64); ... // Odd part ... // Advance block pointers ...
    (borland.public.delphi.language.basm)
  • Re: Getting at the binary data in an Image object
    ... (I tried the above code in Mozilla, ... function getRequestObj() { ... var ret = null; ...
    (comp.lang.javascript)
  • Re: for/in loop Array gotcha
    ... var exists=; ... There is nothing "odd" about that in my view only that the 'in' operator is not implemented in older browsers respectively the script engines they come with, e.g. in Netscape 4 the 'in' operator use will give a syntax error, the same for IE 5/Mac if I remember a recent discussion here correctly. ...
    (comp.lang.javascript)
  • Re: AJAX Problem
    ... var table = document.getElementById; ... function createRequestObject() { ... tmp = new XMLHttpRequest; ...
    (comp.lang.javascript)
  • Re: How to return values from a java script function
    ... var value2 = 20; ... Not modify values external to it. ...
    (microsoft.public.scripting.jscript)