Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get the java dropdowns out of the .htm and into a .js ?

    Hi Everyone.
    I learned html from htmlgoodies and found whatever javascripts I use, so I do not REALLY know what I am doing.
    This did not stop me from setting up a web site that uses javascripts. The site is dedicated to mixed breed dogs, and I use javascripts to navigate.
    Say you want to see what a cross between a beagle and a golden retriever looks like. I have 3-letter abbreviations for dog breeds (beagle is 'bgl' golden retriever is 'grt') and the page for a beagle crossed with a golden is bglgrt.htm, and for a purebred beagle is bglbgl.htm.
    I have one page where you can select both breeds from a drop-down list and it uses this script (I won't post the lists because they are so long, if you want to see them you can go to http://www.mixedbreeddog.info/breeds.htm:
    _______________________________
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Original: Nicholas McConnell -->
    <!-- Idea by: Nicholas McConnell -->

    <!-- Begin
    site = "http://www.yoursite.com"; // Do not include the final "/"
    function combineMenus(frm, breed1, breed2) {
    with (frm) {
    str = breed1.options[breed1.selectedIndex].value;
    str += breed2.options[breed2.selectedIndex].value;
    url = str + ".htm";
    window.location.href = url;
    }
    }
    // End -->
    </script>
    ________________________________________

    This part of it is actualy ok. But I also have it set up so that you can get to a page for a mixed breed from a page for ONE of the purebreds. So if you are at the page for a beagle, you can select golden retriever from a single drop down list. The script for this is:

    ___
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Original: Nicholas McCodnnell -->
    <!-- Idea by: Nicholas McConnell -->

    <!-- Begin
    site = "http://www.yoursite.com"; // Do not include the final "/"
    function combineMenus(frm, breed2) {
    with (frm) {
    str = breed2.options[breed2.selectedIndex].value;
    url = "grt" + str + ".htm";
    window.location.href = url;
    }
    }
    // End -->
    </script>
    __

    example for the golden at http://www.mixedbreeddog.info/grtgrt.htm

    This turned out to be not a great idea, because I have a separate little script AND list for every page that I have for a purebred. If I want to make a change (like when I notice I spelled Weimaraner incorrectly) I have to go in and modify html code in all the individual pages.

    There has got to be a better way and I would be very grateful to anyone who could explain to me how to do it. I was thinking that I could create a .js file and call it up, but I do not know how to transfer the information from the page I am coming from. In this case, how to I get the 'grt' info etc.

    Thanks in advance also for reading this long post from a newbie.

    PS I noticed after posting that there is a member named "Beagle". There is NO connection and it had no influence on me choosing the beagle as an example.
    Last edited by zircon; 06-13-2006 at 04:43 PM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Put the Javascript into a separate file (eg. nav.js) and then link it into every page

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

    You then only have one place to change the Javascript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Im note sure how many pages are involved but there cold be a list of all Xbreed pages available to all pure breed pages

    this list couls be searched for a match of the two breeds

    ii the url includes both beed names, idealy with a separater

    if a match of each the two breeds the link made

    this list could be in the form of an external JavaScript avaiable to all pure beed pages.

    proably best with a serverside submission but could all be client side
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #4
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall
    Put the Javascript into a separate file (eg. nav.js) and then link it into every page

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

    You then only have one place to change the Javascript.
    Yes, this is what I want to do, but I do not know how. If the call for the nav.js comes from a page for one of the purebred dogs (say 'grtgrt.htm'), how do I take the information to nav.js that it should use 'grt' as a variable?
    Sorry if this is garbled, but I really do not know what I am doing.
    Thanks again for the help.


  •  

    Posting Permissions

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