Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 21:02:04 -0600
<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...
.
- References:
- Newbie Question - variable name in getElementById() method doesn't seem to work
- From: spivee
- Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- From: DJ Majestik
- Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- From: McKirahan
- Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- From: spivee
- Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- From: spivee
- Newbie Question - variable name in getElementById() method doesn't seem to work
- Prev by Date: Re: skyscraper ad staying on current page
- Next by Date: Re: Reordering DIV sections
- Previous by thread: Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- Next by thread: Re: Newbie Question - variable name in getElementById() method doesn't seem to work
- Index(es):
Relevant Pages
|