SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Indexof()

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    446
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Indexof()

    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?

    Code:
    <html>
    <body>
    
    <script type="text/javascript">
    var str="Bob , Brittany , Brian";
    document.write(str.indexOf(",") + "<br />");
    </script>
    
    </body>
    </html>
    Code:
    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;
       }

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    446
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    dooh!

    Code:
    //var txt=document.innerHTML=xmlhttp.responseText;
          var txt=xmlhttp.responseText;
          var txt = txt.indexOf(",");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •