Results 1 to 2 of 2

Thread: Dynamic Contact List

  1. #1

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Arrow Dynamic Contact List

    I have a company directory on my webiste. I'd like to be able to have a text file, each different contact name will be on a separate line, with the contact information of the person. I would like to dynamically create the company directory page by editing the directory text file and the page be created by what's inside. So, here are my questions:
    1) How can I get a text file to be read from a webpage?
    2) Has anyone ever done this and if so, got some code to share?
    3) Am I going about this the wrong way? Thanks, Jeremy
    He who listens well, speaks well.

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    As far as I know, ordinary textfiles aren't understood by HTML-pages or JavaScript.
    I think you can better make it a js-file and link that within your page.
    Create the contact list as an array of objects. I hope you understand how to create and manage objects within JavaScript. It's very useful once you can get grip on it.

    Here's an example:
    Code:
    //I've made an add method to add stuff to an array easier
    Array.prototype.add = Array_add;
    function Array_add(item)
    {
      this[this.length] = item;
    }
    
    function Contact(par1, par2, par3)
    {
      this.par1 = par1;
      this.par2 = par2;
      this.par3 = par3;
    
      return this;
    }
    
    var ContactList = new Array();
    ContactList.add(new Contact("John", "Doe", 25));
    ContactList.add(new Contact("Mary", "Pierson", 47));
    ContactList.add(new Contact("Roger", "Johnson", 38));
    In other JavaScript you can read / manipulate the contact list as if it was an ordinary array.

    This will display the contact list in a table
    Code:
      document.write("<table border=\"1\">");
      for(var i = 0; i < ContactList.length; i++)
      {
        document.write("<tr><td>" + ContactList[i].par1 + "</td><td>" +
        ContactList[i].par2 + "</td><td>" + ContactList[i].par3 + "</td></tr>");
      }
      document.write("</table>");
    I hope this will help.

Posting Permissions

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



Click Here to Expand Forum to Full Width