Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Need help with javascript!!
Closed Thread
Old 10-29-2006, 01:38 PM   #1 (permalink)
 
Super Techie

Join Date: Jul 2006

Posts: 486

ZeroShade is on a distinguished road

Default Need help with javascript!!

Can anybody help me with some javascript. I got this script off the web and edited as much as I can to suit my page, but I only know so much javascript. Can anybody help me? The problem is that there is an error that was with the original script that I still can't fix, you'll see it when you view the page. My second problem is that when its on its first entry and there are more then 1, the delete button will delete the one after the first one, and if there is only one entry, that entry won't delete at all... can somebody help me with my address book script?

Code:
<!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">

                Address:
                <input type="box" name="address" size="50" id="textbox">

                Phone:
                <input type="box" name="phone" size="50" id="textbox">

                Comments:
                <input type="box" name="comment1" size="50" id="textbox">

                <input type="box" name="comment2" size="50" id="textbox">

                <input type="box" name="comment3" size="50" id="textbox">

                <input type="box" name="comment4" size="50" id="textbox">

                <input type="box" name="comment5" size="50" id="textbox">
								<div id="who">
										 Starting date:
										 <input type="box" name="starttime" size="48" id="textbox2">

										 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>
						<p id="info">Insert the name, address, phone number, and any other information needed. You cannot delete the first entry, therefore, insert an entry and save over it.
			</body>
</html>

__________________
Live And Let Learn.
ZeroShade is offline  
Old 10-31-2006, 02:28 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,686

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default

On the error window, it shows you what the error is. Though, I'm not sure how to fix it. I know very little Java.
__________________

Need website help? PM me!
CrazeD is offline  
Old 10-31-2006, 05:29 PM   #3 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,415

office politics will become famous soon enough

Default

Code:
document.frm2.actual.value = "Record " + (recCount+1)+";  "+arrRecords.length+" saved records";
i've never seen a input type set as box before, so i set another as text.

added some of the final statements to onload in body tag.

the page doesnt error, and can shift through records, but count still doesnt work

Last edited by office politics; 02-01-2009 at 03:06 PM.
office politics is offline  
Old 10-31-2006, 10:42 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

Quote:
Originally posted by CrazeD
On the error window, it shows you what the error is. Though, I'm not sure how to fix it. I know very little Java.
Java and JavaScript are two very different things.
jaeusm is offline  
Old 11-01-2006, 03:34 AM   #5 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,686

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default

Quote:
Originally posted by jaeusm
Java and JavaScript are two very different things.
Shows how much I know about it..

I meant javascript, though.
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On