Results 1 to 3 of 3

Thread: JavaScript null object error

  1. #1
    Join Date
    Mar 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript null object error

    Whenever I click on my Delete button, I get a null object error, which is the following:

    TypeError: null is not an object (evaluating 'document.getElementById('grid').innerHTML')
    The error actually comes from the createMember function in my index.js file which is commented out because it prevents the execution of the code.

    Code:
    function init() {
                   var relateForm = document.getElementById("genealogyForm");
                   relateForm.onsubmit = validate;
        
                   var createBtn = document.getElementById("myCreate");
                   createBtn.onclick = createMember;
                
                  var updateBtn = document.getElementById("myUpdate");
                  updateBtn.onclick = updateMember;
                }
            
            
               function initDelete() {
                var treeForm = document.getElementById("myTreeForm");
                
                var deleteBtn = document.getElementById("myDelete");
                deleteBtn.onclick = deleteMember;
            }
            
            function getUrlVars() {
                 var vars = {};
                 var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                 vars[key] = value;
                 });
                 return vars;
            }
    
            function validate() {
                    
                if (document.forms[0].myFirstName.value == "") {
                alert("Please enter your first name.");
                return false;
                } // end if
                if (document.forms[0].myLastName.value == "") { 
                alert("Please enter your last name.");
                return false;
                } // end if
                if (document.forms[0].myBirthDate.value == "") { 
                alert("Please enter your last name.");
                return false;
                } // end if
                if (document.forms[0].myFatherFirstName.value == "") {
                alert("Please enter your father's first name.");
                return false;
                } // end if
                if (document.forms[0].myFatherLastName.value == "") {
                return false;
                } // end if
                if (document.forms[0].myMotherFirstName.value == "") {
                alert("Please enter your mother's first name.");
                return false;
                } // end if
                if (document.forms[0].myMotherLastName.value == "") { 
                alert("Please enter your mother's last name.");
                return false;
                } // end if
                return true;
            } // end function validate         
    
            //Global variables
            var fName = getUrlVars()["myFirstName"];
            var lName = getUrlVars()["myLastName"];
            var fFirstName = getUrlVars()["myFatherFirstName"];
            var fLastName = getUrlVars()["myFatherLastName"];
            var mFName = getUrlVars()["myMotherFirstName"];
            var mLName = getUrlVars()["myMotherLastName"];
            var birthDate = getUrlVars()["myBirthDate"];
              
            var fatherName = fFirstName + " " + fLastName;
            var motherName = mFName + " " + mLName;
                    
            var msg = ""; 
    		
            var id = 1;
                       
            //Open and create database
    		var mydb = openDatabase('mydb', '1.0', 'my database', 2 * 1024 * 1024);
    
             mydb.transaction(function (t) {
                tx.executeSql('CREATE TABLE IF NOT EXISTS RELATE (ID INTEGER PRIMARY KEY ASC, firstname TEXT, lastname TEXT, fathername TEXT, mothername TEXT)');
             });
    
    
            //function addMember() {
            mydb.transaction(function (t) {
                t.executeSql('INSERT INTO TABLE (firstname, lastname, fathername, mothername) VALUES ("' + fName + '","' + lName + '","' + fatherName + '","' + motherName + '")');
    
                t.executeSql('SELECT * FROM TABLE WHERE firstname = "' + fName + '" AND lastname = "' + lName + '" AND fathername = "' + fatherName + '" AND mothername = "' + motherName + '"', [], function (t, results) {
                   
                   var results = results.rows.length, i;
                        
                   for (i = 0; i < results; i++){
                      msg = "<tr>";
    				  msg +="<td><h3>" + results.rows.item(i).firstname + " " + results.rows.item(i).lastname + "</h3></td>";
    				  msg += "</tr>";
    				  msg += "<tr>";
    				  msg += "<td>" + results.rows.item(i).fathername + " " + "</td>";
    				  msg += "<td>" + results.rows.item(i).mothername + "</td>";
    				  msg += "</tr>";
    				  
                      document.getElementById('message').innerHTML +=  msg;                  
                   }
                }, null);
             });        
            //}
            
            function updateMember (tree) {
    		  	mydb.transaction(function (t) {
    
                t.executeSql('UPDATE TABLE SET fathername = ?, mothername = ? WHERE firstname = ? AND lastname = ?', [fatherName, motherName, fName, lName]); 
                t.executeSql('SELECT * FROM TABLE WHERE firstname = "' + fName + '"', [], function (t, results) {
                   var results = results.rows.length, i;
                   
                        
                   for (i = 0; i < results; i++){
    				  msg +="<p><h3>" + results.rows.item(i).firstname + " " + results.rows.item(i).lastname + "</h3></p>";
    				  msg += "<p>" + results.rows.item(i).fathername + " " + results.rows.item(i).mothername + "</p>";
    				  document.getElementById('message').innerHTML +=  msg;
                   }
                }, null);
             });
            }
              
            function deleteMember () {
                mydb.transaction(function (t) {
                    t.executeSql('DELETE FROM TABLE WHERE ID = ?' [id], success, error);
                });
            }
    I am not sure why the error is showing up.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I see that you have been seeking help in other forums.

    For the benefit of our regulars, please see these threads for reference and further information that may help to assess how to help;

    http://www.dreamincode.net/forums/to...onclick-event/
    http://www.codingforums.com/javascri...t-web-sql.html
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Your question makes little sense to me. No error can come from something that's commented out. Maybe you mean because it's commented out?

    Anyway, the best way for us to solve this is with a link to the problem page. Tell us exactly what we need to do to duplicate the error.

    Please supply a link to the page with the problematic code on your site so we can check it out.

    Please tell us what we have to do, once there, to see the problem happening.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. error: null is null or not an object
    By kristad in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 11-25-2011, 04:59 PM
  2. error: overallTotal is null or not an object
    By newphpcoder in forum JavaScript
    Replies: 0
    Last Post: 11-14-2011, 06:53 AM
  3. Replies: 1
    Last Post: 05-20-2011, 05:05 PM
  4. Error: 'is length' is null or not an object
    By stlntdot in forum JavaScript
    Replies: 3
    Last Post: 10-21-2008, 11:52 AM
  5. HV Menu: Error: 'FrstMbr' is null or not an object
    By bfarwell in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-30-2004, 08:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •