There are tons of questions on passing strings to a javascript function - that's not what I'm asking here. My problem is that I have to pass an integer (a customer ID) as a string to a javascript function from PHP. The reason I have to do this is sometimes a customer ID can have leading zeros, and I do not know how many leading zeros will be needed, so I can't pad or format with leading zeros in javascript.
Here's the PHP that calls my function. The $row is a resulting array from an odbc query.
parse_str("customerId=" . $row["customerId"], $output);
// This is called via AJAX, so returning HTML as response
...
echo "<td><input type='checkbox' id='" . $output["customerId"] . "' onclick='disableAccount(" . $row["userAccountId"] . ", " . $output["customerId"] . ");' checked /></td>
The above works fine, and correctly passes a string with leading zeros to the funtion. Here's part of that function.
function disableAccount(userAccountId, customerId) {
// Do stuff here
}
As an example, I have a customerId of "026608". When the disableAccount function is called, the customerId parameter is parsed as an integer, which strips the leading zero, and I now have a parameter of '26608'.
As I mentioned above, I can't use padding to add a leading zero to the customerId, as there isn't always a leading zero on the customerId. The customerId can also have more than one leading zero.
How can I get my function to parse a string, i.e. "026608" as a parameter with the leading zeros? Thanks in advance!