responseText and IE issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jay10k
    New Member
    • Feb 2008
    • 4

    responseText and IE issue

    Hi, I'm working with the responseText on IE but I have a problem with it

    I make this

    var test = xmlhttpobject.r esponseText;

    alert(test);

    there is no problem with those two lines, the problem is that I'm sending from the server the word "si" and what I get in variable is a 5 characters word.

    Then whe I'm trying to verify the word that I'm recieving with this

    [CODE=javascript] for( var i=0 ; i<test.length ; i++)
    {
    if ( test[i] == 's' )
    if ( test[i+1] == 'i' )
    test="si";
    }

    [/CODE]and then I do

    if ( test == "si")
    document.locati on.href = "url";

    doesn't work and always get into the else statement of the if that didn't put it here.

    When I'm verifiying the what the test variable containt with alert(test[i]) always say Undefined for all the characters even if the string has the letters "s" and "i"

    The funny thing is that this work on Mozilla Firefox like with almost all the other things

    Can someone help me with it?
    Last edited by acoder; Feb 11 '08, 10:59 AM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You're resetting test within the for loop. Use charAt to get the character within the string.

    Comment

    • Jay10k
      New Member
      • Feb 2008
      • 4

      #3
      Ohh sorry I forget one line into the if statement

      for(var i=0; i<test.length ; i ++)

      if(test[i] == 's')
      if(test[i+1] == 'i')
      {
      test = "si"
      break;
      }

      I do actually reset test cause as I said before the string length is of 5 elements and if I compare test == "si" it doesn't match ... even when I'm getting the string back from the server ...


      And thank you anyway for your help I will try as you say ...

      Comment

      • Jay10k
        New Member
        • Feb 2008
        • 4

        #4
        Yes you got it, the problem was resolved thank you very much for your help :)
        Last edited by Jay10k; Feb 11 '08, 07:13 PM. Reason: It works with charAt

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          You're welcome. Post again if you have more questions.

          Comment

          Working...