Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to add an 'Add Information' button to website? (Best Answer Guaranteed)

I finished writing some code. And I want to Display Information at the start (Done that). Then I wanted a button that when you press it, it runs a function. But it says I did not declare the function. How do I fix this?

Code:

<html>

<head>
    <title> Evergreen
    </title>
    <script src="http://www.parsecdn.com/js/parse-1.6.7.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body style="margin:110;padding:0">
    <font face="Magneto" size="16"><div  id="fixedheader">189</div></font>
    <style type="text/css">
        body {
            background-color: #CCC;
            margin: 80px 80px 100px 100px;
        }

        .boxed {
            border: 1px solid #333;
        }

        div#fixedheader {
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            color: #CCC;
            background: #333;
            padding: 20px;
        }

        div#fixedfooter {
            position: fixed;
            bottom: 0px;
            left: 0px;
            width: 100%;
            color: #CCC;
            background: #333;
            padding: 8px;
        }
    </style>
    <center>
    <font face="Arial"> 
    <ul style="list-style: none;" id="list-all-the-facts-given">
    </ul>

 <script type="text/javascript">
      (function(){
      Parse.initialize("uZXJE7ChTK3XMvs3Nsf8hE5ivHWiGLpEimGAnUp1", "zJ9PQfiin6ZY9FXSqxFvYmuA9uOhsRz64jTWoExL");

      function getInformation() {
       console.log("Hi");
       var query = new Parse.Query( "SomeFacts" );
       query.find({ success: function( results ) {
          var output = "";
          for (var i in results) {
            var theInformation = results[i].get("actualInformation");
            var theSource = results[i].get("actualSources");
            var theHeadline = results[i].get("actualTitle");  
            output += "<li>";
            output += "<div class=\"boxed\">"  
            output += "<h2>" + theHeadline + "</h2>";
            output += "<p><pre>" + theInformation + "</pre></p>";
            output += "<b>" + "Source: " + "(" + theSource + ")" + "</b>";
            output += "<h5></h5>"  
            output += "</div>";  
            output += "</li>";
          }      
        document.getElementById("list-all-the-facts-given").innerHTML = output;

        }, error: function( error ) {
          alert("There was an error, this error is " + error.message );
        }
      })
     }
          getInformation();

          function doPrompt() {
     var SomeFacts = Parse.Object.extend("SomeFacts");
     var theFacts = new SomeFacts();
     var theHeadline = prompt("Enter title for the information:");      
     var supplyInfo = prompt("Enter information:");      
     var supplySRC = prompt("Enter source:");
     theFacts.set( "actualInformation" , supplyInfo );
     theFacts.set("actualSources", supplySRC);
     theFacts.set("actualTitle", theHeadline);      
     theFacts.save(null, {
       success: function(theFacts) {
           console.log("Objects was saved successfully. Object ID: " + theFacts.id);
       },
       error: function(theFacts, error) {
         alert('Failed to create new object, with error code: ' + error.message);
       }
     })
          }

          doPrompt();
    getInformation();
  })();


    </script></font></center>
</body>

</html>

[MOD: Edited to show code blocks]

Your code is not displaying, could you please post it so we can try to help? :)

I've just edited the post to show the code.

Do you guys have an idea for what it could be?

Don't know if you're still having a problem with this but you need to post the error log. That will show us which function is causing the issue.