Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help me with this(stupid) database

    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
    <html>
    <head>
    <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>";
    document.write(line1.line2,line3,line4);
    }
    function DataB(name,surname,email,telnumber){
    this.name=name;
    this.surname=surname;
    this.email=email;
    this.telnumber=telnumber;
    this.PrintData=PrintData;
    }
    function addnew(n,s,e,a){
    i=1;
    i=new DataB(n,s,e,a);
    i++;
    document.form1.clear.click();
    }
    function WiewRec(){
    var newWind=window.open("","WIEW DATABASE","toolbar=no,status=no,width=300,height=500");
    for(var j=0,j<i,j++){
    i.PrintData();
    }
    }
    </script>
    </head>
    <body>
    <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();">
    </form>
    </body>
    </html>
    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.
    Last edited by Jojosh; 05-09-2004 at 03:44 PM.

  • #2
    New Coder
    Join Date
    Apr 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cmon people please help.Does anybody here?Pleaseeeeeeeeeeee!!!!

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I saw 2 errors in your code:
    Code:
    for(var j=0,j<i,j++){
    should be
    Code:
    for(var j=0;j<i;j++){
    and
    Code:
    document.form1.clear.click();
    There is no element named "clear" in the <form>. Maybe you meant
    Code:
    document.form1.reset();
    ?

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

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    <html>
    <head>
    <title>The Mini JavaScript Mini-Database</title>
    <script>
    function init()
    {
    recidx=0
    record = new Array ()
    }
    function addrec()
    {
    record[recidx]=new Array ()
    record[recidx][0]=document.bio.firstname.value
    record[recidx][1]=document.bio.lastname.value
    record[recidx][2]=document.bio.age.value
    record[recidx][3]=document.bio.sex[0].checked
    record[recidx][4]=document.bio.income.selectedIndex
    recidx++
    document.bio.clear.click()
    }
    function viewrec()
    {
    viewwin=window.open("","View_Records","scrollbars=yes,width=640,height=400")
    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> "
    record[j][4]+"<p>")
    }
    viewwin.document.writeln("<p><form><input type=button value='Close Record View'
    onClick='window.close()'></form>")
    }
    </script>
    </head>
    <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>
    </select></p><p>
    <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>
    </form>
    <p><p>Thanks for using the mini database!</p>
    </body>
    </html>
    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.

  • #7
    New Coder
    Join Date
    Apr 2004
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It seems that nobody wants to answer.

  • #8
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To add the records to a database, you need to handle it on the serverside.

    Which serverside language and which database are you using?
    /Daniel


  •  

    Posting Permissions

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