SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple if statement not working

    I am using Prototype Ajax.Updater and am trying to read the response text but it doesn't seem to read. Here is a snippet of my code:
    Code:
    function showFormResponse(req)
    {
    	var response = req.responseText;
    	$('message').innerHTML = req.responseText;
    	if(response == '1'){
    		alert('booh');
    	}
    }
    Now var response is actually holding the exact response text when I printed it out. I don't get why the if statement is not catching the 1 even though it is shooting out that response. I am probably missing something real simple. Thanks in advance.

  2. #2
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Removes quotes
    Use this statement if(response == 1) instead of if(response == '1')

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow can't believe that did it. Thanks. I assumed that when I echo the response out in php as a string then it would come back the same.

  4. #4
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No Problem whatsoever
    If you lose your patience you lose half of battle

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sajjad,
    How come it doesn't want to match up strings? Why only integers? I've tried matching: "Loading..." both with single quotes and double quotes. The response is exactly the same, but won't go in the if.

  6. #6
    SitePoint Zealot sajjad's Avatar
    Join Date
    May 2005
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the answer is in ur question find it???????
    If you lose your patience you lose half of battle


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
  •