0

I have an input box in my HTML

<input id="myInput">

I've tried

var myString = (document.getElementById("myInput").toString());

and

var myString = String(document.getElementById("myInput"));

but doing console.log(myString); will always return [object HTMLInputElement]

How do I get console.log(myString) to actually return the string the user entered

Enkrypton
  • 39
  • 1
  • 2
  • 15

2 Answers2

0

By using document.getElementById("myInput") you get the whole input object. This object contains many properties, which you can access. If you want the user input, you can access it by using document.getElementById("myInput").value

Peter
  • 15
  • 4
0

I believe the object should have a "data" property you can access for the values using dot notation. Also this link has some solutions How to convert the html object to string type?

j3ff
  • 5,719
  • 8
  • 38
  • 51