SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding Values From Database to Javascript Form

    I have a Javascript form example here for a project I'm working on. However, I have to pull data from a relational database in Access and stick it in the USER DEFINED section. What's the best way to get the information from the database to properly populate the form fields?

    Here's the Javascript in which I need to insert the database values.

    PHP Code:
    <script language="JavaScript1.1">

    function 
    dynoMenu(txt,url)
    {
    this.txt=txt;
    this.url=url
    this.opened=false;
    this.cnt=0;
    this.sub=new Array();
    this.l=null;
    this.i=null;
    }

    //---==+0+==--- USER DEFINABLE SECTION ---==+0+==---

    mymenu  = new dynoMenu(null,null); 
    mymenu.sub[0] = new dynoMenu("Cathegory 1",null);
    mymenu.sub[0].sub[0] = new dynoMenu("Sub 1-1",null);
    mymenu.sub[0].sub[0].sub[0] = new dynoMenu("Sub 1-1-1","file111.html");
    mymenu.sub[0].sub[0].sub[1] = new dynoMenu("Sub 1-1-2","file112.html");
    mymenu.sub[0].sub[1] = new dynoMenu("Sub 1-2","file12x.html");
    mymenu.sub[0].sub[1].sub[0] = new dynoMenu("Sub 1-2-1","file121.html");
    mymenu.sub[0].sub[1].sub[1] = new dynoMenu("Sub 1-2-2","kaka.html");
    mymenu.sub[0].sub[2] = new dynoMenu("file 1-3-1","file131.html");

    mymenu.sub[1] = new dynoMenu("Cathegory 2",null);
    mymenu.sub[1].sub[0] = new dynoMenu("Sub 2-1",null);
    mymenu.sub[1].sub[0].sub[0] = new dynoMenu("Sub 2-1-1","file211.html");
    mymenu.sub[1].sub[0].sub[1] = new dynoMenu("Sub 2-1-2","file212.html");
    mymenu.sub[1].sub[1] = new dynoMenu("Sub 2-2",null);
    mymenu.sub[1].sub[1].sub[0] = new dynoMenu("Sub 2-2-1","file221.html");
    mymenu.sub[1].sub[1].sub[1] = new dynoMenu("Sub 2-2-2","file222.html");

    mymenu.sub[2] = new dynoMenu("Cathegory 3",null);
    mymenu.sub[2].sub[0] = new dynoMenu("Sub 3-1",null);
    mymenu.sub[2].sub[0].sub[0] = new dynoMenu("Sub 3-1-1","file311.html");
    mymenu.sub[2].sub[0].sub[1] = new dynoMenu("Sub 3-1-2","file312.html");
    mymenu.sub[2].sub[1] = new dynoMenu("Sub 3-2",null);
    mymenu.sub[2].sub[1].sub[0] = new dynoMenu("Sub 3-2-1","file321.html");
    mymenu.sub[2].sub[1].sub[1] = new dynoMenu("Sub 3-2-2","file322.html");

    mymenu.sub[3] = new dynoMenu("file 4-1-1","file411.html");
    //---==+0+==---END OF USER DEFINABLE SECTION ---==+0+==---

    function clearmenu(m)
    {
    options  m.options;
    for (var 
    i=options.lengthi>=1i--) options[i] = null;  
    options[0].selected true;
    }

    function 
    setmenu(m,optArray)
    {
    options  m.options;
    clearmenu(m);
    if(
    optArray!=null)
     {for (var 
    0optArray.lengthi++) 
         
    options[i+1]=new Option(optArray[i].txt,optArray[i].url); 
     }
    options[0].selected true;
    }

    function 
    setitems(N)
    {
    clr=false;
    if(
    N<depth-1)
    {
    mmm mymenu;
     for(
    i=0;i<=N;i++) 
      {
    sel = eval("document.mm.m"+i);
       
    selinx sel.selectedIndex-1;
       if(
    selinx<0) break;
       
    mmm=mmm.sub[selinx];
      }
     
    sel = eval("document.mm.m"+(i));
     
    setmenu(sel,mmm.sub);
     
    i++;
     while(
    i<depth)
      {
    sel = eval("document.mm.m"+(i));
       
    clearmenu(sel);
       
    i++;
      }
    }

     
    sel = eval("document.mm.m"+N);
     
    selinx sel.selectedIndex;
     if(
    selinx>0
       {
    urrl=sel.options[selinx].value;
        if(
    urrl!='null')
        
    openwin(urrl); 
       }
    }


    function 
    openwin(url)
    {if(
    url!=nullwindow.open(url,"_blank");}

    var 
    depth=3;
    var 
    d=document;


    d.writeln("<FORM name='mm'>");
    for(
    i=0;i<depth;i++)
     {
    d.writeln("<SELECT name='m"+i+"' onChange='setitems("+i+")'>");
      for(
    j=0;j<5;j++) d.writeln("<option >----Please, select-----");
      
    d.writeln("</select>");
     }
    d.writeln("</form>");
    setitems(0,0);
    </script> 

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the databse on the server? If so, fougeddaboudit. If you are storing the MDB locally, then MAYBE you can interact with it with ActiveX, but don't quote me on that.

    For server-side interaction with the DB, you need a server-side language (PHP, Perl, ASP, CFML, Java, etc.)
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •