HighDots Forums  

array problem

Javascript JavaScript language (comp.lang.javascript)


Discuss array problem in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Trevor Stapleton
 
Posts: n/a

Default array problem - 02-02-2004 , 03:07 PM






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

Reply With Quote
  #2  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: array problem - 02-02-2004 , 03:22 PM






Trevor Stapleton wrote:

Quote:
I have an external javascript file named record.js in the file is the
following sample:
with as its first line

var rec = new Array;

I hope?

Quote:
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
add the phrase (attribute)
language="javascript"
!

Quote:
I have had spectacular success in getting none of it to work,
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.

Quote:
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.
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
http://www.heuveltop.nl/BasCB



Reply With Quote
  #3  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: array problem - 02-02-2004 , 07:17 PM



Bas Cost Budde <bas (AT) heuveltop (DOT) org> writes:
Quote:
add the phrase (attribute)
language="javascript"
!
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 (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #4  
Old   
Bas Cost Budde
 
Posts: n/a

Default Re: array problem - 02-03-2004 , 03:33 AM



Lasse Reichstein Nielsen wrote:

Quote:
language="javascript"

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
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
http://www.heuveltop.nl/BasCB



Reply With Quote
  #5  
Old   
Michael Winter
 
Posts: n/a

Default Re: array problem - 02-03-2004 , 05:19 AM



On Tue, 03 Feb 2004 09:33:41 +0100, Bas Cost Budde <bas (AT) heuveltop (DOT) org>
wrote:

[snip]

Quote:
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.
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 (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
  #6  
Old   
Trevor Stapleton
 
Posts: n/a

Default Re: array problem - 02-03-2004 , 07:01 AM



On Mon, 02 Feb 2004 21:22:55 +0100, Bas Cost Budde <bas (AT) heuveltop (DOT) 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, ??";

Reply With Quote
  #7  
Old   
@SM
 
Posts: n/a

Default Re: array problem - 02-03-2004 , 07:42 AM



Trevor Stapleton a ecrit :
Quote:
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
<a href="#" onclick="prt='';
for(var i=0;i<rec.length;i++)prt+=rec[i]+'<br>';
tuc=window.open(); tuc.document.write(prt);">See all records</a>
???

Quote:
the function would return a string containing "Degee, Ann, ??";
First
would be better moving away each space after coma in your records
rec[1]="Boyes,Florence 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=rec[4]; alert(ptr);">Degge</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=rec[4].plit(','); alert(prt[0]);">Ann</a>


More examples here :
http://perso.wanadoo.fr/stephane.mor...c/reccords.htm
- 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:stephaneOTER_MOImoriaux (AT) wanadoo (DOT) fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.