I have a MySQL table that is being displayed on a webpage. I have a button for each row that toggles a function using a value from the row :
<button id="loginButtonSmall" onclick="resumeApplication(<?php echo $row['newApplicationNumb']; ?>)">
Pickup where we left off
</button>
Value of $row['newApplicationNumb']
displays correctly further up on the page.
Here $row['newApplicationNumb']
= 359786918929342363.
Then I have :
function resumeApplication(applicationID) {
var newApplicationNumb = applicationID;
alert(newApplicationNumb);
}
The alert returns : 359786918929342340.
So it changes the last 2 digits from 63 to 40 each time...
I've looked around and really don't understand how it could change the value like this...
Any clues would be very much appreciated!
See this answer: What is JavaScript's highest integer value that a number can go to without losing precision?
The short answer is that your number is too big and the reliability is lost. I'd use a string value instead.
The highest integer value in javascript is +/-9007199254740991. If you really need to store higher values use library BigInteger
.
The second option is not to pass the parameter as an integer but as a string. Replace this:
<button id="loginButtonSmall" onclick="resumeApplication(<?php echo $row['newApplicationNumb']; ?>)">
Pickup where we left off
</button>
With this:
<button id="loginButtonSmall" onclick='resumeApplication("<?=$row['newApplicationNumb']?>")'> // Added quotation marks
Pickup where we left off
</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With