-4

I want a user to input a number into input type="tel" or type="number" and then to make a variable with this number for further calculations. So far it is unable to identify a number. Any ideas?

function digit() {
    var num = document.getElementById('inpt');
    document.body.innerHTML = num;
}
<input onchange="digit()" type="tel" name="numb" id="inpt" />
Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
CeeJay
  • 569
  • 2
  • 6
  • 16
  • Possible duplicate of [How do I get the value of text input field using JavaScript?](https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript) – Jared Smith Sep 12 '17 at 14:21
  • Set an event listener to changes of this input, then update the value of variable as it is mentioned above – Sergey Sep 12 '17 at 14:21
  • 2
    Telephone numbers, despite the name, aren't *numbers*. They're strings. Don't tell me my mobile is `7712345678`. It's `07712 345 678`. My work number may well be `020 1234 5678 ext. 10`. Or `1 (408) 555-1234`. – T.J. Crowder Sep 12 '17 at 14:21

1 Answers1

0

try this

<script>
function digit() {
    var num = document.getElementById('inpt').value;
    document.body.innerHTML = num;
}
</script>

if it's not correct try this

console.log(document.getElementById('inpt'))

and show the object in browser console

Lionel R
  • 66
  • 1
  • 7