immunity Posted June 19, 2007 Share Posted June 19, 2007 I try to craft Ajax. I got a .php file which it gives $sInfo variable values 0 (if no rows returned ) or 1 (if one or more rows returned) with javascript i get this echo on var results. I want to create if (results ==0 ){ give element value ="not exists" } if(results ==1) {give element value ="exists"} but compiler doesnt go inside one of these 2 if I checked without if and element get value = result (display in broswer 0 or 1) how i can compare results ? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Customer Account Information</title> <script type="text/javascript"> var url = "GetCustomerData.php?id="; // The server-side script function handleHttpResponse() { if (http.readyState == 4) { if(http.status==200) { var results=http.responseText; if(results==1) { results ="exists"; document.getElementById('divCustomerInfo').innerHTML = results; } if (results==0) { results ="not exist"; document.getElementById('divCustomerInfo').innerHTML = results; } } } } function requestCustomerInfo() { var sId = document.getElementById("txtCustomerId").value; http.open("GET", url + escape(sId), true); http.onreadystatechange = handleHttpResponse; http.send(null); } function getHTTPObject() { var xmlhttp; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); if (!xmlhttp){ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object </script> </head> <body> <p>Enter customer ID number to retrieve information:</p> <p>Customer ID: <input type="text" id="txtCustomerId" value="" /></p> <p><input type="button" value="Get Customer Info" onclick="requestCustomerInfo()" /></p> <div id="divCustomerInfo"></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/56223-solved-problem-on-compare-variable-inside-if-variable-a-value/ Share on other sites More sharing options...
nogray Posted June 19, 2007 Share Posted June 19, 2007 add an alert(results); before you compare to see what the actuall value of results. Also, results is a string, so your comparisson should be if (results == "1") with quotes around the one finally, you can use if (results == "1") { ... } else { ... } Link to comment https://forums.phpfreaks.com/topic/56223-solved-problem-on-compare-variable-inside-if-variable-a-value/#findComment-277758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.