The first code box produces the result I expected (4).
The second code box produces a -1 on what I believe is the same string (ie var txt=document.innerHTML=xmlhttp.responseText; displays “Bob , Brittany , Brian” when it’s not commented out). Any ideas why? Is it possible “xmlhttp.responseText” isn’t a string?
<html>
<body>
<script type="text/javascript">
var str="Bob , Brittany , Brian";
document.write(str.indexOf(",") + "<br />");
</script>
</body>
</html>
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var div = document.createElement('div');
div.setAttribute('id', 'link_container');
div.setAttribute("style","background-color:white;");
div.style.width = '300px';
div.style.height = '100px';
div.style.margin = '-15px 0px 0px 75px';
//var txt=document.innerHTML=xmlhttp.responseText;
var txt = str.indexOf("Brittany");
document.getElementsByTagName('body')[0].appendChild(div);
document.getElementById('link_container').innerHTML=txt;
}