By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

array problem

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Trevor Stapleton wrote:
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?
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"
!
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.
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

Jul 20 '05 #2

P: n/a
Bas Cost Budde <ba*@heuveltop.org> writes:
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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
Lasse Reichstein Nielsen wrote:
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

Jul 20 '05 #4

P: n/a
On Tue, 03 Feb 2004 09:33:41 +0100, Bas Cost Budde <ba*@heuveltop.org>
wrote:

[snip]
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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5

P: n/a
On Mon, 02 Feb 2004 21:22:55 +0100, Bas Cost Budde <ba*@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, ??";
Jul 20 '05 #6

P: n/a
@SM
Trevor Stapleton a ecrit :

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>
???
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:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.