Proper Use of Nan

How would I implement NaN and have Inavlid input display in a

To do this I have to use isNaN to verify that numerical values are input.
I just want it to display "Invalid input" whenever a non numeric value is put in either of the two first text boxes. this is my fiddle link

<!DOCTYPE html>
    <html lang="en">
        <meta charset="utf-8">

        <script type="text/javascript">


window.onload = function(){

 function add_number(){

var first_number = document.querySelector("#tb1").value;
  var second_number = document.querySelector("#tb2").value;
  var First = parseInt(first_number);
  var Second = parseInt(second_number);
  var result = First + Second;


  <h1>Add two number using text box as input using javascript</h1>
Enter First Number : <br>
<input type="text" id="tb1" name="TextBox1">
<br> Enter Second Number : <br>
<input type="text" id="tb2" name="TextBox2">
<br> Result : <br>
<input style="width: 50%" type="text" id="tb3" name="TextBox3" >
<input onclick="add_number()" type="button" id="b1" value="GO" />


71 thoughts on “Proper Use of Nan”

Leave a Comment