PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] How do I get the output to display inside the div after the user fills in the prompts?

 August 16, 2022     html, javascript, output, variables     No comments   

Issue

When I test this code in a browser the prompts pop up just fine, but then there's nothing on the screen after filling them all out. Is there something I'm missing...?

<!DOCTYPE html>
<html>
    <head>
        <title>Mad Libs</title>
    </head>
    <body>
    <div id="out"></div>
        <script>
        var properName = prompt("Enter a proper name");
        var verb = prompt("Enter a verb (past tense)");
        var verb2 = prompt("Enter a second verb (past tense)");
        var adj = prompt("Enter an adjective");
        var adj2 = prompt("Enter another adjective");

        var out = "Roses are red. Violets are blue. <br/>";
        out += properName + "left town without wearing a shoe. <br/>";
        out += properName + " " + verb + "<br/>";
        out += "And " + properName + " " + verb2 + "<br/>";
        out += "But I am " + adj + " " + properName + "thought. <br/>";
        out += "And kind of " + adj2 + " too!";
            
        document.getElementByID('out').innerHTML = out;
        </script>
    </body>
</html>

Solution

document.getElementByID should be document.getElementById:

<!DOCTYPE html>
<html>
    <head>
        <title>Mad Libs</title>
    </head>
    <body>
    <div id="out"></div>
        <script>
        var properName = prompt("Enter a proper name");
        var verb = prompt("Enter a verb (past tense)");
        var verb2 = prompt("Enter a second verb (past tense)");
        var adj = prompt("Enter an adjective");
        var adj2 = prompt("Enter another adjective");

        var out = "Roses are red. Violets are blue. <br/>";
        out += properName + "left town without wearing a shoe. <br/>";
        out += properName + " " + verb + "<br/>";
        out += "And " + properName + " " + verb2 + "<br/>";
        out += "But I am " + adj + " " + properName + "thought. <br/>";
        out += "And kind of " + adj2 + " too!";
            
        document.getElementById('out').innerHTML = out;
        </script>
    </body>
</html>



Answered By - Spectric
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing