title: Delete object from parse.com using Handlebars.js
body: <p>What I have is two inputs for the user to enter in a first name and last name which gets saved to the database. Next using Handlebars.js I looped through the objects in the database to create a list of all "contacts" and added a button that when clicked should delete that contact.</p>
  
  <p><img src="https://i.stack.imgur.com/K82MI.jpg" alt="Example of what i&#39;m looking for"></p>
  
  <p>The problem is I cant delete the object.
  Below is the code i have used so far.</p>
  
  <pre><code>&lt;script id="template" type="text/x-handlebars-template"&gt;
  &lt;table&gt;
  &lt;tr&gt;
  
  &lt;td&gt;
  &lt;input value={{FirstName}}&gt;&lt;/input&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input id="EditLname" value={{LastName}}&gt;&lt;/input&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;button id=del&gt;delete&lt;/button&gt;
  &lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>the rest of the important code below.</p>
  
  <pre><code>$(window).load(function () {
          var Contact = Parse.Object.extend("Contact");
          var query = new Parse.Query(Contact);
          query.equalTo("objectId");
          query.find({
              success: function (results) {
  
                  for (i = 0; i &lt; results.length; i++) {
                      var data = ({
                          FirstName: results[i].attributes.FirstName,
                          LastName: results[i].attributes.LastName
                      });
                      var template = Handlebars.compile($('#template').html());
  
                      var html = template(results);
  
                      $("#main").append(template(data));
                  }
              },
              error: function (error) {
                  alert("Error: " + error.code + " " + error.message);
              }
          });
  
          $(document).on("click", "#del", function () {
              myObject.destroy({
                  success: function (myObject) {
                      // The object was deleted from the Parse Cloud.
                  },
                  error: function (myObject, error) {
                      // The delete failed.
                      // error is a Parse.Error with an error code and description.
                  }
              });
          });
      });
  </code></pre>
  
  <p>the above gives "Uncaught ReferenceError: myObject is not defined" in the console log. But I have that code to show my thought pattern more than anything.</p>
  
  <p>Just in case anyone is unsure, what I want is when the button beside john smith is clicked "john smith" will be dropped/ deleted from the database.</p>
  
  <p>EDIT: Basically I want to get <a href="http://jsfiddle.net/x4rWF/" rel="nofollow noreferrer">This</a> working with Handlebars.</p>
  
  <p>EDIT: <a href="https://www.parse.com/questions/how-to-delete-a-row-while-using-handlebars-js" rel="nofollow noreferrer">This Question</a> asked on Parse.com</p>