Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Cómo imprimir la salida de los nombres de los jugadores usando JS y HTML

Hola, soy nuevo en el uso de JS y HTML y sigo practicando el lenguaje, estoy tratando de imprimir el nombre de usuario de ambos jugadores pero sin usar la alerta. Quiero imprimir los nombres de los jugadores y luego cambiarlo usando CSS, pero tengo problemas con la forma más simple de imprimir las entradas de los usuarios. Tengo esto hasta ahora y me preguntaba por qué no funciona. Cualquier ayuda será apreciada.

 function welcome(){ var first = document.getElementById("FirstName").value; var last = document.getElementById("LastName").value; var Print_name = "Welcome " + first +" "+ last; console.log(Print_name); }
 <!DOCTYPE html> <html> <head> <title>Print Names</title> </head> <body> <form method="get"> <label for="Player1Name">Player 1 Name:</label> <input type="text" id="Player1Name" name="player1Name" placeholder="Name"><br> <label for="Player2Name">Player 2 Name:</label> <input type="text" id="Player2Name" name="player2Name" placeholder="Name"><br> <input type="submit" value="Submit" class="btn"> </form> <script> /*javascript code here*/ </script> </body> </html>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debería encontrar un elemento HTML (con id="Player1Name") y (con id="Player2Name").

Pruébalo código en HTML

 <input type="submit" value="Submit" class="btn" onclick="welcome()">

Pruébalo código en JavaScript

 function welcome(){ var first = document.getElementById("Player1Name").value; var last = document.getElementById("Player2Name").value; var Print_name = "Welcome " + first +" "+ last; alert(Print_name); }
about 4 years ago · Juan Pablo Isaza Report

0

su document.getElementById hace referencia a la identificación incorrecta.

Entonces, si su campo de texto se define como

 <input type="text" **id="Player1Name"** name="player1Name" placeholder="Name">

Entonces, lo que debería estar haciendo es document.getElementById(" Player1Name ").value

Lo mismo ocurre con el campo Player2Name.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!