Title: Javascript Addition Not Working
Last modified: April 19, 2018

---

# Javascript Addition Not Working

 *  Resolved [carl2e](https://wordpress.org/support/users/carl2e/)
 * (@carl2e)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/javascript-addition-not-working/)
 * This is probably has a simple answer but I have been working on this for hours
   without being able to figure it out. I have the following function that retrieves
   a value ‘spot’ from input field ‘myInput’ and calculates a value ‘tmpspot’.
 * For this example I am entering the number ’23’ in the field “myInput” (type=”
   number”). When I pass ’23’ to the function as shown below the function properly
   returns ’44’. However, when I comment out the line “tmpspot = tmpspot – (0 – 
   spot) ;” and instead use the previous line “tmpspot = tmpspot + spot ;”, the 
   function returns ‘2123’, as though it concatenated the two numbers instead of
   adding them together.
 * What am I missing?
 * function NextSpot() {
    var spot = document.getElementById(“myInput”).value; var
   tmpspot = spot % 2 ; tmpspot = (tmpspot – (0 – spot)) – 1 ; tmpspot = 65 – spot;
   tmpspot = tmpspot / 2 ; tmpspot = parseInt(tmpspot); // tmpspot = tmpspot + spot;
   tmpspot = tmpspot – (0 – spot) ; document.getElementById(“demo”).innerHTML = 
   tmpspot ; return true ; }

Viewing 1 replies (of 1 total)

 *  Thread Starter [carl2e](https://wordpress.org/support/users/carl2e/)
 * (@carl2e)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/javascript-addition-not-working/#post-10198471)
 * I realized that php was treating the variables as string variables, not numeric
   variables. For now, I including the following line to make sure that the variable‘
   spot’ is an integer:
 * spot = parseInt(spot) ;
 * The function is now working.

Viewing 1 replies (of 1 total)

The topic ‘Javascript Addition Not Working’ is closed to new replies.

 * ![](https://ps.w.org/custom-css-and-javascript/assets/icon-256x256.png?rev=3061295)
 * [Custom CSS and JavaScript](https://wordpress.org/plugins/custom-css-and-javascript/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-css-and-javascript/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-css-and-javascript/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-css-and-javascript/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-css-and-javascript/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [carl2e](https://wordpress.org/support/users/carl2e/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/javascript-addition-not-working/#post-10198471)
 * Status: resolved