Wanting to improve a javascript page.
Hi all,
I have a page that really needs some help. The page is at http://shoutingrock.org/troop214/not.shtml Here is the problem. When I need to add a scout I have to renumber the top fields. I would like to just insert the scout in the proper position.
IE.
If I want to add a scout between this two I need to change all the [2]'s to [3]'s first and then add the new scout
address[1] = "Street Address"
town[1] = "Town"
state[1] = "State"
zipcode[1] = "Zip"
phone[1] = "Phone"
rank1[1] = "Rank"
patro[1] = "Patrol"
leade[1] = "Leadership position"
emai[1] = "E-Mail address"
fileid[1] = "1"
address[2] = "123 Coleman Way"
town[2] = "Woodbadge"
state[2] = "MA"
zipcode[2] = "11111"
phone[2] = "(800)got-rope"
rank1[2] = "Tenderfoot"
patro[2] = "Scorpions"
leade[2] = "Patrol Leader"
emai[2] = "[email protected]"
fileid[2] = "2"
Also the name of the scout is at another spot on the page.
Anyone have an idea on how I could do this with an array like this?
"John Scout";"Street Address";"Town";"State";"Zip";"Phone";"Rank";"Patrol";"Leadership position";"E-Mail address"
Thanks in advance for your help.
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Mark Hensler posted this at 07:05 — 23rd August 2000.
He has: 4,048 posts
Joined: Aug 2000
try this:
number = "0"
address[number] = "Street Address"
town[number] = "Town"
state[number] = "State"
zipcode[number] = "Zip"
phone[number] = "Phone"
rank1[number] = "Rank"
patro[number] = "Patrol"
leade[number] = "Leadership position"
emai[number] = "E-Mail address"
fileid[number] = "1"
number++ //increment the count
address[number] = "123 Coleman Way"
town[number] = "Woodbadge"
state[number] = "MA"
zipcode[number] = "11111"
phone[number] = "(800)got-rope"
rank1[number] = "Tenderfoot"
patro[number] = "Scorpions"
leade[number] = "Patrol Leader"
emai[number] = "[email protected]"
fileid[number] = "2"
number++ //increment the count
address[number] = "XXX"
town[number] = "XXX"
state[number] = "XXX"
//etc.
'number' will increment each time, creating the next element in the arrays
Mark Hensler
If there is no answer on Google, then there is no question.
Vincent Puglia posted this at 14:27 — 23rd August 2000.
They have: 634 posts
Joined: Dec 1999
Hi Jim,
There may be any number of solutions to your question. May I ask why you want to insert a record within the established array?
If the answer has to with the array length and the MakeArray function, kill the makeArray function and use:
var ArrayName = new Array();
the length will take care of itself and the only compatibility issues are with Netscape ver 2 and IE ver 3 (both of which are probably long gone from the web).
If the answer has to do with alphabetizing: you can use the built-in array.sort() method, or create your own.
Vinny
Where the world once stood
the blades of grass cut me still
Jim Shilt posted this at 16:50 — 23rd August 2000.
They have: 268 posts
Joined: May 1999
Hi Vincent,
I was kind of hoping you would answer this one.
As for your first question. We have scouts come into the troop every year and some boys only add their names when they get a computer. Also some boys leave. I really wanted to make it easier for me to add boys and keep the names in alpha order.
In response to your second statement. I'm not smart enough to understand the sort without seeing a working script. I am a script modifier
Thanks for your future help.
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Vincent Puglia posted this at 03:10 — 25th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi Jim,
Try keeping me away I'll have something for you tomorrow. (had to send one of the kids off to school today, so a bit tired.)
Another question though: you want to simply sort a predefined list of scouts? Or, do that & submit new scout info to yourself or a dbms?
Vinny
BTW: the site looks a lot better than the last time I saw it -- around when you were putting up the calendar, right?
Where the world once stood
the blades of grass cut me still
Jim Shilt posted this at 13:43 — 25th August 2000.
They have: 268 posts
Joined: May 1999
Hi Vinny,
Thanks for saying the site looks better.
As far as the list. The scout gives me a slip filled out with the information and parent approval to put it on the site. I add the info using notepad. So I already know everything about the scout. I just want a better way to add the names and keep them in alpha order by scout name.
Thanks again
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Mark Hensler posted this at 18:26 — 25th August 2000.
He has: 4,048 posts
Joined: Aug 2000
Jim-
You have a good life goal.
Philippians 4:20!
Vincent Puglia posted this at 17:19 — 26th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi Jim,
I moved all of the form-related functions to a js file (which gets included in the html). Just cut&paste the scoutData.js info as is into an empty file and name the file.
You need to make 4 changes to the html file (noted below)
New scouts are added with the fillScout function. follow the template. You don't have to put them in any order, the scoutSort will alphabetize them.
You might want to kill the fileID cell -- it's not used -- if you do change the scoutRecLength var to 10.
changes to the html page
1) <script language='javascript' src='scoutData.js'></script>
2)
3)
<script language="javascript">
</script>
4) kill all value references in the input text tags (the onLoad=disp loads the initial data)
contents of scoutData.js
var scoutRecLength = 11;
var scouts = new Array();
fillScouts("---- Select ----|Street Address|City/Town|ST|Zip|Phone|Rank|Patrol|Leadership position|E-mail address|fileID");
fillScouts("Zzzzzz|9999 Coleman Way|Woodbadge|MA|11111|(800)got-rope|Tenderfoot|Scorpions|Patrol Leader|[email protected]|2");
fillScouts("Erik Eagle|111 Eureka Drive|Roundtable|PA|99999|(800)got-fire|Eagle|Turkey|Bugler|[email protected]|3");
fillScouts("Clinton|1600 Pennsylvania Avenue|Washington|DC|99999|(800)play-sax|Eagle|Turkey|Prez|[email protected]|5");
fillScouts("Frankie First Class|123875415714513-a Long Hike Circle|Canyon Echo|ho|12321|(800)got-tent|First Class|Graduates|Chaplain Aide|[email protected]|4");
fillScouts("Tommy Tenderfoot|123 Coleman Way|Woodbadge|MA|11111|(800)got-rope|Tenderfoot|Scorpions|Patrol Leader|[email protected]|2");
function disp(selObj, formObj)
{
var index = 0;
var recScout = new Array();
for (i=0; i < selObj.length; i++)
if (selObj.options[i].selected)
index = selObj.options[i].value * scoutRecLength;
for (i = 0; i < scoutRecLength; i++, index++)
recScout[i] = scouts
;
with (formObj)
{
street.value = recScout[1];
town.value = recScout[2];
state.value = recScout[3];
zipCode.value = recScout[4];
phone.value = recScout[5];
rank.value = recScout[6];
patrol.value = recScout[7];
leader.value = recScout[8];
email.value = recScout[9];
}
}
function fillScouts(str)
{
var index = scouts.length;
tmpArray = str.split("|");
for (i = 0; i < tmpArray.length; i++)
scouts[index++] = tmpArray[i];
}
function fillSel()
{
scoutSort();
var len = scouts.length / 11;
document.write("")
for (i = 0; i < len; i++)
{
newItem = i*11;
document.write("" + scouts[newItem] + "");
}
document.write("");
}
function scoutSort()
{
var len = scouts.length / 11;
var i = j = k = org = offset = 0;
for (i = 1; i < len; i++)
{
org = i * 11;
if (org < scouts.length)
{
for ( j = 1; j < len ; j++)
{
offset = j*11;
if ( scouts[offset] > scouts[org] )
{
for (k = 0; k < scoutRecLength; k++)
{
tmp = scouts[offset];
scouts[offset++] = scouts[org];
scouts[org++] = tmp;
}
j--;
}
}
}
}
}
if you need anything, let me know
Vinny
Where the world once stood
the blades of grass cut me still
Jim Shilt posted this at 03:46 — 30th August 2000.
They have: 268 posts
Joined: May 1999
Hi Vinny,
I tried to make the changes. I didn't get it right. Would you look at http://www.shoutingrock.org/troop214/not.shtml and see what I missed?
Thanks again.
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Vincent Puglia posted this at 07:18 — 30th August 2000.
They have: 634 posts
Joined: Dec 1999
Sorry Jim,
Forgot to tell you I changed some of the element names as well.
Also: the fillScouts(blahablah) call should be on one line. That is, this:
fillScouts("---- Select ----|Street Address|City/Town|ST|Zip|Phone|Rank|Patrol|Leadership position|E-mail address|fileID");
should be 1 line, not 3. Because for all intents and purposes, it is passing a string. And strings must be on one line.
Finally, the only function I have in the html page (besides GateKeeper) is:
function new_window(url) {
I killed all the old code for the arrays (function choice(), etc).
Hope this fixes it
Vinny
Where the world once stood
the blades of grass cut me still
Jim Shilt posted this at 13:43 — 30th August 2000.
They have: 268 posts
Joined: May 1999
THANKS THANKS THANKS
Shouts of joy above for Vinny.
I got the script to work. Thank you for all your hard work. I ended up taking out the sort function. With the names and addresses on the same line it is easy to sort manually and I wanted to sort on last names. It is amazing how much shorter the script is when you use arrays. I am going to have to learn how to use them
Again thanks.
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Vincent Puglia posted this at 14:57 — 30th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi Jim,
You're welcome, glad it filled the bill, and speaking of the bill -- it's in the snail mail; it should get to you by the time my kid hits my age.
I also noticed you placed everything into the HTML page rather than a js file. Personally, I would keep it, make a few changes on the function and array names, and use the same scoutData.js file for all the dbms pages in the site (troop214 and merit).
Only change I would make now is the following line:
this:
newItem = i * 10;
should be:
newItem = i * scoutRecLength;
That's why this line is there:
var scoutRecLength = 10;
If you ever decide to add some more information (next of kin, number of awards, etc.), you will only have to change the var (and the new field to the scout's record). You won't have to scratch your head wondering why "i * 10"; you won't even have to search for it.
BTW: not having a bible nearby, what are your & Max's philippian verses?
Vinny
Where the world once stood
the blades of grass cut me still
Jim Shilt posted this at 17:04 — 30th August 2000.
They have: 268 posts
Joined: May 1999
Hi Vinny,
I left the script on the not.shtml page so that hopefully people would not be able to figure out the names and addresses of my real page. (The one with the real scout names and addresses on it.)
On the other page that I update regularly I will put it in a js file.
Now for the learning part. Would you be so kind as to explain what the functions do? Also how would I modify the script so that the js file can be used for the merit badge list? Would I just make a fillMerit function and a fillSel for the Merit badge list? Do I need to make a field similar to street.value = recScout[1]; but that reads street.value = recMerit[1]?
If I could understand how this all works I could add another page that I have been wanting to add that shows what a scout has left for their next advancement.
As for the Philippians reference.
Philippians 4:8,9
Finally, brothers, whatever is true, whatever is noble, whatever is right, whatever is pure, whatever is lovely, whatever is admirable-if anything is excellent or praiseworthy-think about such things. Whatever you have learned or received or heard from me, or seen in me- put it into practice. And the God of peace will be with you.
This verse is good even if you don't believe in God. If everyone would stop thinking about things that are bad, (murder, rape, stealing) think how much nicer the world would be to live in.
Philippians 4:20
To our God and Father be glory forever and ever. Amen
Thanks again for your help. Someday maybe I will be able to help you out.
My goal in life is found in Phillipians 4:8-9
shoutingrock.org/troop214
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.