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

115
Vistas
Issue with updating innerHMTL with javascript prompt on load

I'm attempting to update the tag with id = "content" with prompted info. For some reason the window.onload function isn't working. I've tried moving the around to no success. Apparently the div is null but i'm not sure how to remedy this. Thanks!

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Exercise 3</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <p><strong>User Information:</strong></p>
        <div id=”content”>...</div>



        <script type="text/javascript">
            
            function promptFunc() {
                let text; 
                let name = prompt("What is your full name?", "Name");
                let age = prompt("How old are you?", "Age");
                if (name == null || age == null || name == "" || age ==""){
                  text = "User did not enter information";
                }else {
                    text = "Hi, my name is "+name+" and i'm "+age+" years old.";
                }
                document.getElementById("content").innerHTML = text;
            }

            window.onload=function(){
                promptFunc();
            }
            
        </script>
    </body>

</html>

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Your Code has a mistake in ”content” quotes. you have given the wrong quotes in div id="content">

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Exercise 3</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <p><strong>User Information:</strong></p>
        <div id="content">...</div>



        <script type="text/javascript">
            
            function promptFunc() {
                let text; 
                let name = prompt("What is your full name?", "Name");
                let age = prompt("How old are you?", "Age");
                if (name == null || age == null || name == "" || age ==""){
                  text = "User did not enter information";
                }else {
                    text = `Hi, my name is ${name} and i'm ${age} years old.`;
                }
                document.getElementById("content").innerHTML = text;
            }

             window.onload=function(){
                promptFunc();
            }
        </script>
    </body>

</html>
about 4 years ago · Santiago Gelvez Denunciar

0

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Exercise 3</title>
    <meta charset="UTF-8">
</head>

<body>
    <p><strong>User Information:</strong></p>
    <div id="content">...</div>

    <script type="text/javascript">
        function promptFunc() {
            let text;
            let name = prompt("What is your full name?", "Name");
            let age = prompt("How old are you?", "Age");
            if (name == null || age == null || name == "" || age == "") {
                text = "User did not enter information";
            } else {
                text = "Hi, my name is " + name + " and i'm " + age + " years old.";
            }
            document.getElementById("content").innerHTML = text;
        }

        window.onload = function() {
            promptFunc();
        }
    </script>
</body>

</html>

Use the double quotation("") in id="content"

about 4 years ago · Santiago Gelvez 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