0

After I add name value from textbox, and then name value didn't display on webpage and it just display [object Object][object Object], I tried converting from objects to string but don't solve problem.

document.getElementById("test").innerHTML = obj.toString(); -> don't work.

Check all my code at below:

<script>

       const obj = 
       [{
        iname: "",
        iprice: ""
       }];

    function btn()
    {
               
                var name = document.getElementById('Iname').value;
                var price = document.getElementById('Iprice').value;

                obj.push({
                    iname: name,
                    iprice: price
                });

                document.getElementById("test").innerHTML = obj;
    }

    </script>

1 Answers1

0

Try this

document.getElementById("test").innerHTML = JSON.stringify(obj);

It's what I use to debug objects

Link Strifer
  • 546
  • 1
  • 3
  • 7