SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2000
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using an external script to write out
    some html to build a menu.
    How can I pass a parameter to this script so
    I can change the menu depending upon what page
    I am on??

    <script src="mainmenu.js" type="text/javascript"></script>

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Encapsulate the actual code in a function with parameters defined. Then you will simply call that function like any other.

    i.e.
    <script src="menuscript.js" language="javascript></script>
    <script language="javascript">
    menuBuilder("index")
    </script>

    Where menuscript is your included file and menuBuilder is the function within that file. The function would then take the string parameter of "index" and do the appropriate parsing and output.

    ------------------
    Wayne Luke
    Internet Media Provider

    [This message has been edited by wluke (edited February 10, 2000).]

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2000
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could it be written like this:
    <script src="menuscript.js" language="javascript>menuBuilder("index")
    </script>

  4. #4
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Not for every browser as they currently interpret the script tag.

    Personally what I like to do is set up global script variables within the <HEAD></HEAD> tags of my page and then the linked in script files can access those and perform anything they need to do based on the global variables which set the page parameters. An example of this would be (following your menu question):
    <head>
    normal header stuff
    <script language=Javascript>menu="index";nextpage="cl08192";prevpage="cl08190";currpage="cl08191";</script>
    <script language=javascript src="/menu.js"></script>

    Then menu.js can act upon the menu variable and display the appropriate menu.

    ------------------
    Wayne Luke
    Internet Media Provider

    [This message has been edited by wluke (edited February 11, 2000).]


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •