Jump to content

Losing Leading Zeros on Variables


davidz

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/66168-losing-leading-zeros-on-variables/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.