While I get Inputs from text box,and adding those input if i leave space then my result comes with NAN.
Asked
Active
Viewed 87 times
-4
-
4can you provide with your code !! – Jack jdeoel Nov 20 '19 at 13:40
-
1[How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Andreas Nov 20 '19 at 13:41
-
1Hard to see what you did wrong without the code. Our crystal balls are broken. Show sample input and expected output. Providing those details will result in a nice answer. Put effort into your question and people will put effort into the answers. Sounds like you need to check it is a number before you add. – epascarello Nov 20 '19 at 13:41
-
Welcome to SO. This question is too broad. Please take a look at the [help section](https://stackoverflow.com/help) of the site, particularly this article on [how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Andy Nov 20 '19 at 13:42
-
https://stackoverflow.com/questions/1303646/check-whether-variable-is-number-or-string-in-javascript – epascarello Nov 20 '19 at 13:44
-
@DavidJawHpan for (var i = 0; i < strSplit.length; i++) { var sum = parseInt(sum) + parseInt(strSplit[i]) } document.getElementById("resultStr").value = sum; } – Ajay R Nov 21 '19 at 09:47
1 Answers
0
Try to find if the entered text is a number or not and then try to add them.
you can use below snippet.
It is just to give you the idea.
var ToCheck=sometext;
var IsNotaNumber=isNaN(ToCheck);//check both the inputs
if(!IsNotaNumber)
{
//add the numbers
}

Its_Ady
- 308
- 2
- 10