25 users online (2 members and 23 guests)  


  Results 1 to 11 of 11

Related

  1. Replies: 0
  2. Replies: 2
  3. Adding values to an external .js Javascript file?    Forum: Javascript Forum
    Replies: 3
  4. call external Javascript(PHP) with passing value    Forum: Javascript Forum
    Replies: 2
  5. [SPLIT]passing values to an external .js file    Forum: Javascript Forum
    Replies: 37
  1. #1
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652

    Question passing values to an external .js file

    Searched on pass and passing value without luck, so here's my query:

    The sig.js file is activated within and at the end of each .htm file via

    <SCRIPT SRC="sig.js" language=JavaScript> </SCRIPT>

    the contents of the sig.js file is

    mydate=new Date();
    year=mydate.getFullYear();

    document.write("Copyright<SUP>_</SUP> 2002-"+ year + ", ");


    (The _ underline character being #169 - the copyright symbol.)

    How do I pass a value other than 2002 to the sig.js file so I don't have to create separate files for each 'creation' year, ie., one for 1999, 2000, 2001, 2002, and so on?

    (It could be done by making the contents of the sig.js file a function, I'm guessing, but then how does one activate that function at a specific location at the beginning or end of the .htm file?)


    [ It goes without saying that the entire process is more complicated that what's shown above, but what's above is the essence of the primary problem encountered - passing values to an external script file, thereby allowing it to be made universally available to .htm pages with only the beginning years differing from each other. ]
    Last edited by benzden; 08-21-2002 at 12:58 PM.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Your right, making it a function is the way to go.

    Code:
    function stamp(creation) {
    mydate=new Date();
    year=mydate.getFullYear();
    
    document.write("Copyright<SUP>_</SUP> " + creation + "-"+ year + ", ");
    }
    This is the *.js file for inclusion. Include it anywhere near the top, <head> is fine.
    Then call it like this -

    Code:
    <script language="JavaScript">
    stamp('1999')
    </script>
    Works fine, just tested it.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    O U T S T A N D I N G ! ! ! THANK YOU VERY MUCH! (As an experienced programmer, this kind of 'coding threshhold' is just what I need to really get into .js programming.)

    I added the function to my already existing jamrent.js, jamrent1.js (one folder deep) and jamrent2.js (two folders deep) files and moved the

    <SCRIPT language=JavaScript SRC="../../jamrent2.js"> </SCRIPT>


    inside the </HEAD> at the top of the file and

    I T W O R K S ! !

    at

    http://signalhill.jamrent.com

    (Look inside the source to see how it's configured.) The function inside the jamrent2.js file is (the endings of some wide lines are cut-off ...)

    function sig(firstYR) {
    mydate=new Date();
    year=mydate.getFullYear();
    document.write("<A NAME=bottom></A><B><CENTER ID=mendu2>"
    + " <A HREF='javascript:history.go(-1);'><IMG ALT=back BORDER=0 WIDTH=60 H ...
    + " <A HREF='javascript:history.go(-2);'><IMG ALT=back BORDER=0 WIDTH=60 H ...
    + " <A HREF=#bottom TARGET=_top><IMG ALT=CloseFrames BORDER=0 WIDTH=50 HEI ...
    + "<BR>"
    + "<BR> <A HREF=../../jamlinks.htm TARGET=_top><IMG ALT=JamRent BORDER=0 WIDTH ...
    + " <A HREF=#middle><IMG ALT=middle BORDER=0 WIDTH=65 HEIGHT=16 SRC=../../...
    + " <A HREF=#top><IMG ALT=top BORDER=0 WIDTH=40 HEIGHT=16 SRC=../../i/!top ...
    document.write("<P ID=copyrite><A ID=text0 HREF='javascript:location.reload(0)
    + " <SUP><A ID=copysym HREF=../../local/copyrite.htm>_</A></SUP>"
    + " <A ID=text0 HREF=../../jamrent.css> " + firstYR + "-" + year + "</A>, "
    + " <A HREF=../../ben.htm TARGET=_top><IMG ALT=Benny BORDER=0 WIDTH=32 HEIGHT= ...
    + " <A HREF=../../shao.htm TARGET=_top><IMG ALT=ShaoSyanSheng BORDER=0 WIDTH=3 ...
    + "<BR>Author &#38; Webmaster - All pecuniary rights reserved"
    + "<BR><A HREF='javascript:PopMenu()' TARGET=_self>Pop-upMenu</A>(TaskBar)"
    + "<BR>");
    document.write("last modified: "+document.lastModified+"</P>"
    + "<SCRIPT LANGUAGE='JavaScript' SRC=../../jamrent2.js> </SCRIPT>");
    }


    Now, I need to fine tune it - separating the menu items from the purely copyright signature items into two separate calls is the first step - and start revising all 800+ of my .html files to now eliminate all that redundant coding in each of them. Can also use the same technique to call the URL surrounding headings for each page. Will be very busy for the next couple weeks.
    Last edited by benzden; 08-21-2002 at 04:48 PM.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    800+? eek.

    I see why you are researching included files now...urk...

    Glad it works for you
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Just a thought...

    Using a decent text editor (textpad.com, or vim.org ) you could do a macro to find & replace in all selected files. Might save you a big job.

    Actually, if the code is identical in each case, you could probably do something in a DOS Batch file.

    Failing that, you could get a c++ compiler and make a quick executable...

    Its gotta be better than amending 800+ pages! It would be quicker to learn enough of the basics of c++ to write the above than to change them all manually.

    that kind of job would put me off web-design ...
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  6. #6
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Hey, the only chance I get to look at some of those pages is when making major revisions such as this one. Most of them have text that also needs to be updated. Some have links that are no longer valid and many need new links to web sites that didn't exist years ago.

    Just updated the http://signalhill.jamrent.com source code to now include 3 separate calls to the jamrent2.js file functions. The ('SignalHill', 'dcomic25') call coding worked the first time - it's nice being an experienced programmer.

    This is something I've been looking for almost a year - and it really is going to make everything else a lot easier and more efficient - albeit not as friendly to those who have JavaScript turned off or can't get it to work - like my oldest nephew with his Dell Computer with Windows 2000 on it. But, like the increasingly obsolete Netscape, a lot of what's being used to surf the net nowadays isn't going to be around much longer -- I'm assuming that JavaScript will always be around.

  7. #7
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Okay, now that I'm really into this and have added another year's worth of work to my TO DO list, here's the next 'programming' question (I never learned C or C++ but have looked at it a lot):

    How can I call another function (within the same .js file) from within the primary call function? In other words, a using BASIC language reference, what is the equivalent of a SUB or sub-routine call?

    I'm testing this at http://cyriac-fhp.com and want to move the SELECTIONS FORM containing an alphabetical list of the couple hundred sub-domains relative to that 2nd level domain into the primary menu table shown at the top and bottom of that (and probably every other) page. With resizing of the text, it will fit under "origins" in the first cell to the left. (May move it there within the .js file until I can separate it again, so that it can also be shown inside the associated "new" menu box without being redundant.)

  8. #8
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Ah. Got ya.

    it is easy to call another function within another function. Just use the same syntax you would normally.

    Two things to remember: JS looks UP for a function, so the first function has to be literally above the second function in your code.

    Secondly, a variable declared in the 'mother' function may not necessarily by accesable by the 'child' function, so you may have to pass it along with the function.

    If thats not clear, fair enough, I am way too drunk @ the mo to be on a computer, so post and I will try to clarify with my hangover 2morow
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  9. #9
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Thanks, will check it out some time before Monday this weekend is a very busy one off the computer for me.

    This is all being done within the document.write process, so "normal call" is the problem - the normal call was tried once but without the called source above the other, so will retry that and a few variations and report back here.

    This is all very powerful stuff! It pretty much obviates the need for the right click no see my source code elimination process, which will be a minor problem since I do want people to be able to see my source code to see what I'm doing. (Will allow access to my source files via the signature/copyright block - as is done now with fewer files being involved.

    Did notice the document.write process in Danny Goodman's JavaScript Bible but bypassed it as too time consuming until I noticed how easy it was this past week and stopped long enough to smell the roses and get your help to finally figure it all out.

  10. #10
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    O U T S T A N D I N G - 2 ! !

    It worked on the first, err (nothing works on the 1st - coding errors always interfere) 2nd attempt. Now, this opens up all kinds of possibilities to minimize redundancy, thereby eliminating the need to make the same changes to more than one file -- THEREBY ALLOWING INSTANTANEOUS changes to hundreds of web pages simultaneously.

    QuietDean, you are a MASTER of your craft and great TUTOR. This has been like being in a graduate level class on JavaScript without having to leave the comfort of my home.
    The "question - response" process being almost immediate, thanks to you, by the way, and this higher level of discourse forum are some of the best things I've encountered on the web over the past half-dozen years.

    [ The old Compuserve technical forums, accessed via DOS browsing, were sort of like this one in their immediacy and intelligence value. ]

  11. #11
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Thanks Benzden.

    I recently got offered a post of 'Tutorial Writer' for a php resource site. After your kind words, I may just take it up.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread