string value not being recognised as such




What I thought was a string value does not seem to be recognised as
such.
In the following code I extract the string "foo" from an array and
put it into the variable up0
But on checking I find that
(up0=="foo") returns false.

Using the toString function as in
var up0 = update[0].toString();
makes no difference

This is part of a bare bones AJAX demonstration known as
Rasmus' 30 second AJAX Tutorial

The string "foo|foo done" is returned by http.responseText
The aim is to use it to locate <div id="foo"> and to display "foo
done" as its innerHTML
The code returns an errot at
document.getElementById(up0)

A lot of the following lines of code are variables and alerts I have
introduced to try to pinpoint where the problem lies.

Here is the code in more detail followed by the results reported in
the alerts
========================:

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
// the following lines are for debugging
// and not part of the original code
var lgth = update.length;
alert(" ALERT 0 - respose string is " + response);
alert(" ALERT 1 - update length is " + lgth);
var up0 = update[0];
var up1 = update[1].toString();
alert( " ALERT 2 - " + up0 + " and " + up1 ) ;
if(up0=="foo"){
alert(" ALERT 3 - up0 is foo");
}else{
alert(" ALERT 3 - up0 is NOT foo");
}
if(up1=="foo done"){
alert(" ALERT 4 - is done");
} else{
alert(" ALERT 4 - is NOT foo done");
}
document.getElementById("update0").innerHTML = update[0];
document.getElementById("update1").innerHTML = update[1];
// debugging code ends

document.getElementById(up0).innerHTML = update[1];
}
}
}

</script>

<a href="javascript:sndReq('foo')">click me</a>
<div id="update0" > </div>
<div id="update1" > </div>
<div id="foo" > </div>


=========================================
ALERT 0 showed response as 'foo|foo done'
ALERT 1 showed update.length as 2
ALERT 2 showed up0 as 'foo' and up1 as 'foo done'
ALERT 3 reported "up0 is NOT 'foo' "
ALERT 4 reported "up1 is NOT 'foo done' "
<div id="update0" > innerHTML displayed as "foo"
<div id="update1" > innerHTML displayed as "foo done"

And here is the real problem :
document.getElementById(up0).innerHTML = update[1];
triggered an error message saying
document.getElementById(...)is either null or not an object


I would be grateful if someone could explain what is happening here.
Why does variable up0 display like it is a string but when I try to
use it as a value it is not recognised?

TIA
N











TIA
N
.



Relevant Pages