Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
How to display the value of a html user input using JavaScript when a button is clicked?

How to display the value of a html user input using JavaScript when a button is clicked? I've tried, but it gives "[object HTMLInputElement]" instead of the user entered value.

Here's code.

<body>
<p>8 + 7 = ....</p>
<input type="text" name="ans" id="ans1" placeholder="Enter your answer here">
<button type="button" onclick="Game()">OK</button>
<button type="button" onclick="Clear()">Cancel</button>
<br><br>

<h1>A Simple Math Game</h1>
<p>
    <strong>Question 1</strong>
    <span id="question1"></span>
    <span id="answer1"></span>
    <span id="feedback"></span>
</p>

<script>
    document.getElementById("question1").innerHTML= "8 + 7 = ...";
    function Game() {
        let user = document.getElementById("answer1").innerHTML= ans1;
    
    }
        
</script>

Here's the output I got.

8 + 7 = ....32 OK(button) Cancel(button)

A Simple Math Game Question 1 8 + 7 = ... [object HTMLInputElement] // this is the problem..!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

<body>
<p>8 + 7 = ....</p>
<input type="text" name="ans" id="ans1" placeholder="Enter your answer here">
<button type="button" onclick="Game()">OK</button>
<button type="button" onclick="Clear()">Cancel</button>
<br><br>

<h1>A Simple Math Game</h1>
<p>
    <strong>Question 1</strong>
    <span id="question1"></span>
    <span id="answer1"></span>
    <span id="feedback"></span>
</p>

<script>
    document.getElementById("question1").innerHTML= "8 + 7 = ...";
    function Game() {
        let user = document.getElementById("answer1").innerHTML= ans1;
    
    }
        
</script>

<body>
<p>8 + 7 = ....</p>
<input type="text" name="ans" id="ans1" placeholder="Enter your answer here">
<button type="button" onclick="Game()">OK</button>
<button type="button" onclick="Clear()">Cancel</button>
<br><br>

<h1>A Simple Math Game</h1>
<p>
    <strong>Question 1</strong>
    <span id="question1"></span>
    <span id="answer1"></span>
    <span id="feedback"></span>
</p>

<script>
    document.getElementById("question1").innerHTML= "8 + 7 = ...";
    function Game() {
        let user = document.getElementById("answer1").innerHTML= ans1.value;
    
    }
        
</script>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda