array problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor Stapleton

    array problem

    I have an external javascript file named record.js in the file is the
    following sample:

    rec[0]="Blake, Agnes, 18 Sep 1909";
    rec[1]="Boyes, Florence Edith, 1885";
    rec[2]="Carter, Kathleen Sybil, 1910";
    rec[3]="Carty, Joseph, ??";
    rec[4]="Degee, Ann, ??";

    I would access the script with the following
    <SCRIPT SRC="record.js" ></SCRIPT>
    What I have failed to do so far is print any of the
    files contents ( the full list is 163 names ) I think the best method
    would be to pass a variable to a function and have the function return
    the string point to by the variable something like
    ptr=4
    the function would return a string containing "Degee, Ann, ??";

    I have had spectacular success in getting none of it to work,
    I don't and would not ask for others to do it for me, but would
    someone point me in the right direction,

    In parting may I ask would it be better to create a table (containing
    the elements from the above function, if i ever get it working ) in
    the external file or on the html page that it is called from.

    any help would be great fully relieved, and may save my hairline
  • Bas Cost Budde

    #2
    Re: array problem

    Trevor Stapleton wrote:
    [color=blue]
    > I have an external javascript file named record.js in the file is the
    > following sample:[/color]

    with as its first line

    var rec = new Array;

    I hope?
    [color=blue]
    > rec[0]="Blake, Agnes, 18 Sep 1909";
    > rec[1]="Boyes, Florence Edith, 1885";
    > rec[2]="Carter, Kathleen Sybil, 1910";
    > rec[3]="Carty, Joseph, ??";
    > rec[4]="Degee, Ann, ??";
    >
    > I would access the script with the following
    > <SCRIPT SRC="record.js" ></SCRIPT>[/color]

    add the phrase (attribute)
    language="javas cript"
    !
    [color=blue]
    > I have had spectacular success in getting none of it to work,[/color]

    great expression <G> What browser do you use? I use Mozilla, has a nice
    javascript console. Netscape probably has one, too. Helps enormously in
    debugging.
    [color=blue]
    > In parting may I ask would it be better to create a table (containing
    > the elements from the above function, if i ever get it working ) in
    > the external file or on the html page that it is called from.[/color]

    Don't understand. So, you want to create a TABLE tag (with all elements)
    and in there use the data from the record.js script?

    It depends. I think that is a small collection of functions for the job,
    you can put it in the document itself. Maybe you are going to use the
    functionality more often, in which case you might transfer most of it to
    a separate file.

    --
    Bas Cost Budde


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: array problem

      Bas Cost Budde <bas@heuveltop. org> writes:[color=blue]
      > add the phrase (attribute)
      > language="javas cript"
      > ![/color]

      Preferably, add
      type="text/javascript"
      The type attribute is required in HTML 4, and is sufficient in all
      versions. The language attribute is deprecated and should be omitted.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Bas Cost Budde

        #4
        Re: array problem

        Lasse Reichstein Nielsen wrote:
        [color=blue][color=green]
        >>language="jav ascript"[/color][/color]
        [color=blue]
        > Preferably, add
        > type="text/javascript"
        > The type attribute is required in HTML 4, and is sufficient in all
        > versions. The language attribute is deprecated and should be omitted.
        >
        > /L[/color]
        You are extremely right of course! Why didn't I see that myself. Thanks.
        I'm a little ashamed because where I am aware of deprecated features, I
        rather strongly hammer them.

        How about the necessity of whatever type/language indication? Do you
        know browsers that choke on the script if the specifier is absent? I
        just tried in Moz en IE but they execute anyway.

        --
        Bas Cost Budde


        Comment

        • Michael Winter

          #5
          Re: array problem

          On Tue, 03 Feb 2004 09:33:41 +0100, Bas Cost Budde <bas@heuveltop. org>
          wrote:

          [snip]
          [color=blue]
          > How about the necessity of whatever type/language indication? Do you
          > know browsers that choke on the script if the specifier is absent? I
          > just tried in Moz en IE but they execute anyway.[/color]

          The "major" browsers certainly work without a type: they just default to
          JavaScript. I would imagine that recent "minor" browsers would follow suit
          for compatibility reasons. But, as we all know, just because it works, it
          doesn't make it right!

          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • Trevor Stapleton

            #6
            Re: array problem

            On Mon, 02 Feb 2004 21:22:55 +0100, Bas Cost Budde <bas@heuveltop. org>
            wrote:
            In the interest of clarity i think I have better try and explain what
            i am attempting to do:
            -------------------------------------------------------------------
            I have a list of 163 names held in an array named "rec" and indexed as
            shown below, I have declared three variables to use in manipulating (
            when it get it to work) the array.
            What i want to happen is this, a visitor to my site would click on a
            letter of the alphabet for example the letter "D" i want the
            html/javascript to display all the surnames starting with the letter
            "D" in a table, that is the basic task i have set myself, I will
            refine it later to strip the string info smaller sections each in a
            predefined cell of it's own and offering a link to view the entire
            page relating to a name chosen by the visitor, I think I could do this
            quite easily in Visual Basic, but as i am trying to learn ( oh so
            slowly) java script, i feel it's worth staying with.

            the data is held in an external file named record.js I decided to use
            an external file because i think ( right or wrong ) it would be easier
            to keep updated, and i don't like the way it seems to overload the
            html page sticking all that info in the head section.

            I could realy do with some clarity on where the actual table and
            printing to screen should take place, should it be in the .js file or
            on the html page?
            below is the top section of my record.js page
            --------------------------------------------------------------
            var rec=new Array();
            var firstrec=0;
            var lastrec=0;
            var totrec=0;

            rec[0]="Blake, Agnes, 18 Sep 1909";
            rec[1]="Boyes, Florence Edith, 1885";
            rec[2]="Carter, Kathleen Sybil, 1910";
            rec[3]="Carty, Joseph, ??";
            rec[4]="Degee, Ann, ??";
            rec[5]="Devlin, Joseph, ??";
            rec[6]="Devlin, Ryan 1993, ??";
            rec[7]="Fancy, Ann, ??";
            rec[8]="Fancy, Ann, ??";
            rec[9]="Fancy, Anne, 1834";
            rec[10]="Fancy, Elizabeth, ??";

            Comment

            • @SM

              #7
              Re: array problem

              Trevor Stapleton a ecrit :[color=blue]
              >
              > I have an external javascript file named record.js in the file is the
              > following sample:
              >
              > rec[0]="Blake, Agnes, 18 Sep 1909";
              > rec[1]="Boyes, Florence Edith, 1885";
              > rec[2]="Carter, Kathleen Sybil, 1910";
              > rec[3]="Carty, Joseph, ??";
              > rec[4]="Degee, Ann, ??";
              >
              > I would access the script with the following
              > <SCRIPT SRC="record.js" ></SCRIPT>
              > What I have failed to do so far is print any of the
              > files contents ( the full list is 163 names ) I think the best method
              > would be to pass a variable to a function and have the function return
              > the string point to by the variable something like
              > ptr=4[/color]

              <a href="#" onclick="prt='' ;
              for(var i=0;i<rec.lengt h;i++)prt+=rec[i]+'<br>';
              tuc=window.open (); tuc.document.wr ite(prt);">See all records</a>
              ???
              [color=blue]
              > the function would return a string containing "Degee, Ann, ??";[/color]

              First
              would be better moving away each space after coma in your records
              rec[1]="Boyes,Florenc e Edith,1885";
              rec[4]="Degee,Ann,??" ;
              (facultative)

              Then ...
              For instance (to get one of this records) ==>

              simplest :
              <a href="#" onclick="alert( rec[4]);">Degge</a>
              or to use your way :
              <a href="#" onclick="ptr=re c[4]; alert(ptr);">De gge</a>
              or :
              <a href="#" onclick="ptr=4; alert(rec[ptr]);">Degge</a>

              or where you want to write a reccord in your page :
              <script type="text/javascript">
              document.write( rec[4]);
              </script>

              More difficult :
              Name of <a href="#"
              onclick="ptr=re c[4].plit(','); alert(prt[0]);">Ann</a>


              More examples here :

              - open in a window
              - search a record (by name, surname or year)
              - make a listbox (uuu ! 163 options !)

              --
              ******** (enlever/remove [OTER_MOI] du/from reply url) *******
              Stéphane MORIAUX : mailto:stephane OTER_MOImoriaux @wanadoo.fr
              Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

              *************** *************** *************** *************** **

              Comment

              Working...