2 Replies Latest reply on Oct 15, 2013 11:54 AM by Cragvis

    How can I add 2 variables that are entered via input text/number type


      So I have created 2 text fields via composition ready



      $("<input type='text' value='' name='input1' id='input1' size='5'>").appendTo("#Stage");
      sym.$("#input1").css({"position":"absolute","top":"70px", "left":"52px"});
      $("<input type='text' value='' name='input2' id='input2' size='5'>").appendTo("#Stage");
      sym.$("#input2").css({"position":"absolute","top":"90px", "left":"52px"});


      input1 AND input2.


      The user then puts a number in each field.


      I have a 3rd field created to hold the answer. I also made a text field with the name "scorefield" to see if that would work, either will do.


      Then on a button on the stage, the user clicks on it to add those first two numbers together and have the sum appear in the 3rd field or the text field that has the symbol name "scorefield".


      However I can not seem to be able to add the 2 values of the text fields. On the submit button I have:



      var number1 = $("#input1").val();
      var number2 = $("#input2").val();
      var additionresult = number1 + number2;
      answer1.value = additionresult;


      The problem is that it is NOT adding number1 and number2 together!


      If I substitute + for - or / or * it works using those symbols, but if I try to use the plus sign and add the two, it does not work and instead physically adds the numbers next to eachtoher.


      So If I were to put a 5 in field one, and a 2 in field 2, the result comes out to be 52...instead of adding the two values, it places them next to eachother.


      I know those ARE numeric values because any other mathamatical sign works. I can multiplay, subtract and divide those two numbers. I can even check to se if its higher or lower of a value using > or <.


      But when I use the + sign, it breaks.


      Is there some other sign I must use to add two values?