Jump to content

JS Datatype of HTML input type="number"


Raktim

Recommended Posts

I write an HTML code that takes input from the user which type="number". I also keep the user input value into a js variable. But when I check the data type of that variable it shows string...WHY?

<html>
    <head>
    </head>
    <body>
        <input type="number" id="mynumber" value="2"><br>
                
        <p id="demo"></p><br>
        
        <button type="button" onclick="foo()">click here</button>
        
        <script>
             
           function foo ()
            {
                
                var c = document.getElementById("mynumber").value;
                
                document.getElementById("demo").innerHTML = typeof c ;
            }
            
        </script>
  
    </body>
</html>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...