1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

(Solved) Is there a subroutine for HTML?

Discussion in 'Software Development' started by pyritechips, Feb 10, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. pyritechips

    pyritechips Gone but Never Forgotten Thread Starter

    Joined:
    Jun 2, 2002
    Messages:
    26,907
    First Name:
    Jim
    In an earlier thread I said:
    And John (Bassetman) said:
    (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
     
  2. Rockn

    Rockn

    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"
     
  3. juryu

    juryu

    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>
     
  4. pyritechips

    pyritechips Gone but Never Forgotten Thread Starter

    Joined:
    Jun 2, 2002
    Messages:
    26,907
    First Name:
    Jim
    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>
     
  5. juryu

    juryu

    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.
     
  6. pyritechips

    pyritechips Gone but Never Forgotten Thread Starter

    Joined:
    Jun 2, 2002
    Messages:
    26,907
    First Name:
    Jim
    Sorry! Guess I'm too dumb for this. I cut and pasted your code into a test html page and is didn't work.
     
  7. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    Here's the script modified a bit....

    PHP:
    <script>
    function 
    writeletters()
    {
      var 
    '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
     
  8. AbvAvgUser

    AbvAvgUser

    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.
     
  9. brendandonhu

    brendandonhu

    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.
     
  10. pyritechips

    pyritechips Gone but Never Forgotten Thread Starter

    Joined:
    Jun 2, 2002
    Messages:
    26,907
    First Name:
    Jim
    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/
     
  11. brendandonhu

    brendandonhu

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

    PHP:
    function writeletters()
    {
      var 
    '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>
     
  12. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/117992

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice