(Solved) Is there a subroutine for HTML?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

pyritechips

Jim
Thread Starter
Gone but Never Forgotten
Joined
Jun 2, 2002
Messages
26,907
In an earlier thread I said:
All I have to figure out now is how to create a subroutine in html...???:confused:???
And John (Bassetman) said:
PC what kind of subroutine are you talking about?
(Please view my Favourites page to see what I am referring to.)

At the bottom of each section I have home, top and the alphabet to allow one to go directly to any section. But in my code I have merely pasted the same section 26 times, one for each letter of the alphabet. Is there a way to have it in the code only once and have a line of code at the end of each section pointing to it. I remember when I used to code old Basic there was a gosub command
 
Joined
Jul 29, 2001
Messages
21,334
That's not a sub routine....only applies to scripts or programs. What you are loking for is a page jump.
These would be the links
PHP:
<CENTER>
<A HREF="#Top">Top</A>
&nbsp;|&nbsp;
<A HREF="#Bot">Bottom</A>
</CENTER>
This would be where you mark the page place you want the jump to go to.
PHP:
<A NAME="Top">
<A NAME="Bot">
 
Joined
Feb 7, 2003
Messages
18
Are you looking for something like this:
<pre>
&lt;html&gt;
&lt;script&gt;
function writeletters()
{
var a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var i;
for (i=0;i&lt;26;i++)
document.write(a.charAt(i) + "&lt;br&gt;");
}
&lt;/script&gt;
&lt;body&gt;
&lt;script&gt;
writeletters();
&lt;/script&gt;
And these were the letters of the Alphabet!
&lt;/body&gt;
&lt;/html&gt;
</pre>
 

pyritechips

Jim
Thread Starter
Gone but Never Forgotten
Joined
Jun 2, 2002
Messages
26,907
Somehow I don't think I'm explaining myself correctly.

Below is the code I have in place to display the "home top a b c..." etc. It works fine. But it is a lot of code and I have it repeated 26 times, easily doubling the length of the page's code. What I want to know is if there is a way I can have this as a subroutine and have 1 simple, single line of code at the end of each alphabet section refering to it.
PHP:
<tr>
<td colspan="2" width="100%" bgcolor=aliceblue>
<CENTER><b><a href="default.htm">[HOME]&nbsp;</a>
<a href="LinksPage.htm">[TOP]</a>&nbsp;
<a href="LinksPage.htm\#A">[A]</a>&nbsp;
<a href="#B">[B]</a>&nbsp;
<a href="#C">[C]</a>&nbsp;
<a href="#D">[D]</a>&nbsp;
<a href="#E">[E]</a>&nbsp;
<a href="#F">[F]</a>&nbsp;
<a href="#G">[G]</a>&nbsp;
<a href="#H">[H]</a>&nbsp;
<a href="#I">[I]</a>&nbsp;
<a href="#J">[J]</a>&nbsp;
<a href="#K">[K]</a>&nbsp;
<a href="#L">[L]</a>&nbsp;
<a href="#M">[M]</a>&nbsp;
<a href="#N">[N]</a>&nbsp;
<a href="#O">[O]</a>&nbsp;
<a href="#P">[P]</a>&nbsp;
<a href="#Q">[Q]</a>&nbsp;
<a href="#R">[R]</a>&nbsp;
<a href="#S">[S]</a>&nbsp;
<a href="#T">[T]</a>&nbsp;
<a href="#U">[U]</a>&nbsp;
<a href="#V">[V]</a>&nbsp;
<a href="#W">[W]</a>&nbsp;
<a href="#X">[X]</a>&nbsp;
<a href="#Y">[Y]</a>&nbsp;
<a href="#Z"><b>[Z]</a>&nbsp;</B></CENTER>
</td></tr>
 
Joined
Feb 7, 2003
Messages
18
So I did understand you correctly, do the writeletters() function, only instead of printing
<pre> a.charAt(i) + "&lt;br&gt;" </pre>
you print
<pre> '&lt;a href="#' + a.charAt(i) + '"&gt;[' + a.charAt(i) + ']&lt;/a&gt;&nbsp;' </pre>
and call it 26 times instead of writing that whole code 26 times.
 

pyritechips

Jim
Thread Starter
Gone but Never Forgotten
Joined
Jun 2, 2002
Messages
26,907
Sorry! Guess I'm too dumb for this. I cut and pasted your code into a test html page and is didn't work.
 
Joined
Jul 29, 2001
Messages
21,334
Here's the script modified a bit....

PHP:
<script>
function writeletters()
{
  var a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var i;
  for (i=0;i<26;i++)
    document.write("<a href= #" + a.charAt(i) + ">[" + a.charAt(i) + "]</a>&nbsp;");
}
</script>
<body>
<script>
writeletters();
</script>
All you need to do is add the function 26 times....LOL
 
Joined
Oct 3, 2002
Messages
2,281
Why not put the links A to Z in a separate frame? On clicking, the page in the target frame can change accordingly. Then, the code will have to be written only once.
 
Joined
Jul 8, 2002
Messages
14,681
Rather than using Rockn's code to generate links, put his code in a .JS File and use
PHP:
<SCRIPT LANGUAGE=JAVASCRIPT SRC="FILE.JS"></SCRIPT>
I think thats the right syntax there, you might want to doublecheck.
 

pyritechips

Jim
Thread Starter
Gone but Never Forgotten
Joined
Jun 2, 2002
Messages
26,907
Ok it looks like juryu and rockn had it right all along but I was too dumb to understand. Brendan talked me through it and helped me set up his .JS file. His file reduced my page from 54.5KB to 34.7KB! I played with the JS code to custom fit it into my page, eg. I took out "bottom" and inserted [HOME] so it now looks like:

[HOME] [TOP] [A] ...etc.

I want to thank you all for guiding me through this and for helping me tidy up my code and, helping my page run a little smoother.:)

http://members.shaw.ca/pyritechips/
 
Joined
Jul 8, 2002
Messages
14,681
20kb less, not to bad :)
[tsg=yourewelcome][/tsg]
Here is the full script:

PHP:
function writeletters()
{
  var a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var i;
  for (i=0;i<26;i++)
    document.write("<a href= #" + a.charAt(i) + ">[" + a.charAt(i) + "]</a>&nbsp;");
}
document.write("<a href=http://members.shaw.ca/pyritechips/default.htm>HOME </a>")
writeletters();
document.write("<a href=#TOP>TOP</a>")
and
PHP:
<SCRIPT SRC="anchorscript.js"></script>
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top