davidz Posted August 22, 2007 Share Posted August 22, 2007 I have a page that gets created with PHP+MySQL. Then I have some javascript/ajax elements as well. My problem is I am losing the leading zeros on a variable. Here is where PHP builds the onClick: $tabledata .= "<td><a href=# onClick=\"getPropertyData('$row[iD]','$row[TaxID]',$accountnum);\"><img name=\"View$a\" border=\"0\" src=\"images/view.gif\"></a></td>"; The one with the problem is the third variable ($accountnum). This value is normally something like 0029754 or 0689871, etc. Now this part of the page is being created fine. Look at the source code for the completed page: <td><a href=# onClick="getPropertyData('716','SG-FORR-35',0503006);"><img name="View3" border="0" src="images/view.gif"></a></td> Now here is the Javascript for the onClick: function getPropertyData(ID,TaxID,AccountNum) { var HouseImage = getHouseImage(AccountNum) } function getHouseImage(AccountNum) { // Make the XMLHttpRequest object var http = createRequestObject(); var HouseImage; // Open PHP script for requests http.open("GET", "defaultpropertyprocessing.php?Section=HouseImage&AccountNum="+AccountNum, true); http.onreadystatechange = function(){ if(http.readyState == 4 && http.status == 200){ // Text returned FROM the PHP script var response = http.responseText; if(response) { // UPDATE ajaxTest content HouseImage = response; document.getElementById("HouseImage").innerHTML = HouseImage; } } } http.send(null); } I think it is the http.open that is messing it up. I can use DOM Inspector for FireFox and see the link that is being created to GET data from the PHP page. http://www.signingservices.net/defaultpropertyprocessing.php?Section=HouseImage&AccountNum=29754 Where am I losing my zeros? Thanks! David Quote Link to comment Share on other sites More sharing options...
davidz Posted August 22, 2007 Author Share Posted August 22, 2007 For anybody that cares I found the problem. It was treating my variable as a number not a string so it was trying to do math and dropped the leading zeros. This line: $tabledata .= "<td><a href=# onClick=\"getPropertyData('$row[iD]','$row[TaxID]',$accountnum);\"><img name=\"View$a\" border=\"0\" src=\"images/view.gif\"></a></td>"; Needs '' around the $accountnum Like: $tabledata .= "<td><a href=# onClick=\"getPropertyData('$row[iD]','$row[TaxID]','$accountnum');\"><img name=\"View$a\" border=\"0\" src=\"images/view.gif\"></a></td>"; Thanks! David Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.