Niccaman Posted May 26, 2009 Share Posted May 26, 2009 var cut1 = document.getElementById('input1').value; var cut2 = document.getElementById('input2').value; var cut3 = document.getElementById('input3').value; var cut4 = document.getElementById('input4').value; var total = cut1+cut2+cut3+cut4; Why does this output '050500' when entering 0,50,50,0 in the input fields? Link to comment https://forums.phpfreaks.com/topic/159709-solved-variable-being-treated-as-string-rather-than-integer/ Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 Because they're all strings. Try this - var cut1 = parseInt(document.getElementById('input1').value); var cut2 = parseInt(document.getElementById('input2').value); var cut3 = parseInt(document.getElementById('input3').value); var cut4 = parseInt(document.getElementById('input4').value); var total = cut1+cut2+cut3+cut4; Link to comment https://forums.phpfreaks.com/topic/159709-solved-variable-being-treated-as-string-rather-than-integer/#findComment-842380 Share on other sites More sharing options...
Niccaman Posted May 26, 2009 Author Share Posted May 26, 2009 Ty that worked. Link to comment https://forums.phpfreaks.com/topic/159709-solved-variable-being-treated-as-string-rather-than-integer/#findComment-842517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.