ZeroShade Posted October 28, 2006 Share Posted October 28, 2006 I keep getting a problem with this script... it works... but I don't understand what the error means. The error is this: Line 67, character 12, error: 'document.frm1.elements' is null or not an object.Heres the code itself: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Addresses</title> <link rel="stylesheet" href="styles.css" type="text/css" /> <script LANGUAGE="JavaScript">var arrRecords = new Array();var arrCookie = new Array();var recCount = 0;var strRecord="";expireDate = new Date;expireDate.setDate(expireDate.getDate()+730);function cookieVal(cookieName) {thisCookie = document.cookie.split("; ")for (i = 0; i < thisCookie.length; i++) {if (cookieName == thisCookie[i].split("=")[0]) {return thisCookie[i].split("=")[1]; }}return 0;}function loadCookie() {if(document.cookie != "") {arrRecords = cookieVal("Records").split(",");currentRecord(); }}function setRec() {strRecord = "";for(i = 0; i < document.frm1.elements.length; i++) {strRecord = strRecord + document.frm1.elements[i].value + ":";}arrRecords[recCount] = strRecord;document.frm2.add.value = " NEW ";document.cookie = "Records="+arrRecords+";expires=" + expireDate.toGMTString();}function newRec() {switch (document.frm2.add.value) {case " NEW " : varTemp = recCount; for(i = 0; i < document.frm1.elements.length; i++) { document.frm1.elements[i].value = "" } recCount = arrRecords.length; document.frm2.add.value = "CANCEL"; break;case "CANCEL" : recCount = varTemp; document.frm2.add.value = " NEW "; currentRecord(); break; }}function countRecords() {document.frm2.actual.value = "Record " + (recCount+1)+"; "+arrRecords.length+" saved records";}function delRec() {arrRecords.splice(recCount,1);navigate("previous");setRec();}function currentRecord() {if (arrRecords.length != "") {strRecord = arrRecords[recCount];currRecord = strRecord.split(":");for(i = 0; i < document.frm1.elements.length; i++) {document.frm1.elements[i].value = currRecord[i]; } }}function navigate(control) {switch (control) {case "first" : recCount = 0; currentRecord(); document.frm2.add.value = " NEW "; break;case "last" : recCount = arrRecords.length - 1; currentRecord(); document.frm2.add.value = " NEW "; break;case "next" : if (recCount < arrRecords.length - 1) { recCount = recCount + 1; currentRecord(); document.frm2.add.value = " NEW "; } break;case "previous" : if (recCount > 0) { recCount = recCount - 1; currentRecord(); } document.frm2.add.value = " NEW "; break; default: }}if (!Array.prototype.splice) {function array_splice(ind,cnt) {if (arguments.length == 0) return ind;if (typeof ind != "number") ind = 0;if (ind < 0) ind = Math.max(0,this.length + ind);if (ind > this.length) {if (arguments.length > 2) ind = this.length;else return [];}if (arguments.length < 2) cnt = this.length-ind;cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0;removeArray = this.slice(ind,ind+cnt);endArray = this.slice(ind+cnt);this.length = ind;for (var i = 2; i < arguments.length; i++) {this[this.length] = arguments[i];}for(var i = 0; i < endArray.length; i++) {this[this.length] = endArray[i];}return removeArray;}Array.prototype.splice = array_splice;}recCount = 0;loadCookie();countRecords();</script> </head> <body> <form name="frm1"> Name: <input type="box" name="name" size="50" id="textbox"><br> Address: <input type="box" name="address" size="50" id="textbox"><br> Phone: <input type="box" name="phone" size="50" id="textbox"><br> Comments: <input type="box" name="comment1" size="50" id="textbox"><br> <input type="box" name="comment2" size="50" id="textbox"><br> <input type="box" name="comment3" size="50" id="textbox"><br> <input type="box" name="comment4" size="50" id="textbox"><br> <input type="box" name="comment5" size="50" id="textbox"> <div id="who"> Starting time: <input type="box" name="starttime" size="48" id="textbox2"><br> Who's working: <input type="box" name="person" size="48" id="textbox2"> </div> </form> <form name="frm2"> <input type="button" name="first" value="|<< " onClick="navigate('first');countRecords()" id="caption1"> <input type="button" name="previous" value=" < " onClick="navigate('previous');countRecords()" id="caption2"> <input type="button" name="next" value=" > " onClick="navigate('next');countRecords()" id="caption3"> <input type="button" name="last" value=" >>|" onClick="navigate('last');countRecords()" id="caption4"> <input type="box" name="actual" size=23 id="record"> <input type="button" name="add" value=" NEW " onClick="newRec();countRecords()" id="caption5"> <input type="button" name="set" value="SAVE RECORD" onClick="setRec();countRecords()" id="caption6"> <input type="button" name="del" value="DELETE" onClick="delRec();countRecords()" id="caption7"> </form> </body></html> Can somebody help me figure this out on line 67? Link to comment Share on other sites More sharing options...
scott100 Posted October 28, 2006 Share Posted October 28, 2006 Just a general observation Name:<input type="box" name="name" size="50" id="textbox"><br>Address:<input type="box" name="address" size="50" id="textbox"><br> There is no input type "box" it should be textIf you are going to use both name and id then both should have identical valuesYou cannot have any elements with the same id, they should all be unique Link to comment Share on other sites More sharing options...
ZeroShade Posted October 29, 2006 Author Share Posted October 29, 2006 I got the script off the web... I did edit it a bit, but I'm not publishing anything on the internet, so i don't mind that it has some old outdated elements and keywords in it like box. But I still get the same script error, which is really bugging my because I can't figure out why I get it. On top of that, when I want to delete the saved record, it deletes the one after it... this only happens on the first one, can somebody help me edit the script so that the first record can also be deleted? Link to comment Share on other sites More sharing options...
jesh Posted October 30, 2006 Share Posted October 30, 2006 HTML documents are parsed by the browser from the top of the file down to the bottom of the file.Just before your <body></body> element begins, you call "loadCookie()" which, in turn, calls "currentRecord()" which attempts to use the HTML DOM (document.frm1.elements) to access a form which hasn't been rendered by the browser yet."loadCookie()" is read and processed before <form name="frm1"> so, frm1 doesn't exist when loadCookie() is called.You'll either want to call "loadCookie()" on the page load or move that function call to the bottom of the page.Example 1: <body onload="loadCookie();"> Example 2: </form><script type="text/javascript"> loadCookie();</script> </body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted October 31, 2006 Share Posted October 31, 2006 I got the script off the web... I did edit it a bit, but I'm not publishing anything on the internet, so i don't mind that it has some old outdated elements and keywords in it like box. But I still get the same script error, which is really bugging my because I can't figure out why I get it. On top of that, when I want to delete the saved record, it deletes the one after it... this only happens on the first one, can somebody help me edit the script so that the first record can also be deleted?The attribute type 'box' isn't old or outdated, it's non-existent. It was never a part of the spec. The browser sees it and doesn't recognize it, and defaults to text. So you might as well change them all to text, it might be screwing you up somewhere else.As far as more then 1 record getting deleted, it might be because all of them have the same ID. IDs on a document are supposed to be unique like scott mentioned, only 1 element on any document should have a particular ID. Link to comment Share on other sites More sharing options...
ZeroShade Posted October 31, 2006 Author Share Posted October 31, 2006 I switched the box to text and put the onload function in the body element... but I get another error at line 56 saying 'document.frm2.actual" is null or not an object. Why would it be giving this error? Also, how could I go about giving each record its on value so that I can get the delete button working right? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 31, 2006 Share Posted October 31, 2006 <input type="box" name="actual" size=23 id="record">Make the name and id the same thing. Or, in javascript reference it as "record" instead of "actual".As for your other question, I guess my best answer is to just give each element a unique ID. The code is pretty confusing, I'm not sure what you're trying to do with it. The add and delete don't actually add new elements or remove existing ones, so I'm not exactly sure what you're trying to accomplish. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now