View Full Version : Please help me with this(stupid) database

05-09-2004, 03:34 PM
Im trying to make a database,well some kind of it.When you see code,you will almost instantly notice that Im really new to javascript.Can you please answer me where I maked a mistake,it seems to me that i missed something here or I did something that is impossible to do,and because of that the script dosent work.I would be grateful when someone can point to me my mistakes and show me how to do this.Thanks
<title>My Database</title>
<script language="JavaScript" type="text/javascript">
function PrintData(){
line1="<b>Name:</b>" + this.name + "<br>";
line2="<b>Surname:</b>" + this.surname + "<br>";
line3="<b>Email adress:</b>" + this.email + "<br>";
line4="<b>Telephone nuber:</b>" + this.telnumber + "<br>";
function DataB(name,surname,email,telnumber){
function addnew(n,s,e,a){
i=new DataB(n,s,e,a);
function WiewRec(){
var newWind=window.open("","WIEW DATABASE","toolbar=no,status=no,width=300,height=500");
for(var j=0,j<i,j++){
<form name="form1">
<b>Name:</b><input type="text" size="20" name="Namen"><br>
<b>Surname:</b><input type="text" size="20" name="Surnamen"><br>
<b>Email:</b><input type="text" size="30" name="Emailn"><br>
<b>Telephone number:</b><input type="text" size="20" name="tadress"><br>
<input type="button" value="Add Record" onClick="addnew(document.form1.Namen.value,document.form1.Surnamen.value,document.form1.Emailn.value,document .form1.tadress.value);">
<input type="button" value="Wiew Record" onClick="WiewRec();">
Now I know how to kaje some kind of database with arrays,but can this be done with object...I started this only to see is this thing easier to do with using objects.I know that I probably have some grave mistakes in script above,but I just cant find them.Help.

05-09-2004, 05:03 PM
Cmon people please help.Does anybody here?Pleaseeeeeeeeeeee!!!!

Willy Duitt
05-09-2004, 06:44 PM
You do not mention what your problem is.
Or what you are trying to do.

Try turning on script debugging in IE or use Mozilla's Javascript Console so you are alerted to the errors.

05-10-2004, 01:42 AM
My problem is that this dosent work.And my question is this possible at all,i mean this script i wrote -is it possible to make database in this kind of way,and if it is what im doing wrong.As i mentioned above,i would like that someone show me what parts of script are wrong and why.Is I sayed Im trying to make database.So PLEASE can you help me.As for errors I get them,but WHY,WHAT IM DOING WRONG.HELP

05-10-2004, 02:17 AM
I saw 2 errors in your code:

for(var j=0,j<i,j++){ should be
for(var j=0;j<i;j++){



There is no element named "clear" in the <form>. Maybe you meant
document.form1.reset(); ?

Anyway, I think you need to explain better what you want to achieve.

05-10-2004, 02:32 AM
Thanks,very much...I cant belive that I didnt see that.Now for what Im trying to achive...Im trying to male a database,using objects insted arrays.And I just cant make it happen.I dont know why.What I want is this...
You have an form,and when you fill text for name,surname,email,and tel.number then you click button to add that record to database,and then you can click button to view all inputed records.Thats it in nutshell.Same as this,but with objects.
<title>The Mini JavaScript Mini-Database</title>
function init()
record = new Array ()
function addrec()
record[recidx]=new Array ()
function viewrec()
viewwin.document.writeln("<H2>View of "+recidx+" Current Record(s)</H2><p>")
for (var j=0; j<recidx; j++)
{ if (record[j][3]==true) {sex="male"} else {sex="female"}
viewwin.document.write("<H3>"+record[j][0]+" "+record[j][1]+"</H3>")
viewwin.document.write("<H4><i>Age:</i> "+record[j][2]+"<br><i>Sex:</i> "+sex+"<br><i>Income
Level:</i> "
viewwin.document.writeln("<p><form><input type=button value='Close Record View'
<body bgcolor="#FFFFFF" onLoad="init()">
<p><H2>The Tiny JavaScript Mini-Database</H2></p>
<p>To add a record, please complete the following fields and then click Add Record. To view all current
records, click View Records.</p><p>
<form name=bio>
<p>First Name<input type="text" size="10" name="firstname">
Last Name<input type="text" size="10" name="lastname">Age
<input type="text" size="3" name="age"></p><p>
<input type="radio" checked name="sex">Male<br>
<input type="radio" name="sex">Female</p>
<p>Income Range:<br>
<select name="income" size="5">
<option>Scraping By (<$10,000)</option>
<option>Enjoys Ketchup ($10-20,000)</option>
<option>Average Jane ($20-40,000)</option>
<option>Can't Complain ($40-80,000)</option>
<option>Outta My Way ($80,000+)</option>
<input type="button" name="add" value="Add Record" onClick="addrec()">
<input type="reset" name="clear" value="Clear Record">
<input type="button" name="view" value="View Records" onClick="viewrec()"></p>
<p><p>Thanks for using the mini database!</p>
I hope this work in your browser.I want to achive something like above but using object.Can you help me..pretty please.I would like if someone can say if Im on the good road with first script.

05-10-2004, 04:26 AM
It seems that nobody wants to answer. :(

05-10-2004, 03:13 PM
To add the records to a database, you need to handle it on the serverside.

Which serverside language and which database are you using?