...

View Full Version : get the java dropdowns out of the .htm and into a .js ?



zircon
06-13-2006, 05:40 PM
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.

felgall
06-13-2006, 11:14 PM
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.

vwphillips
06-13-2006, 11:20 PM
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

zircon
06-14-2006, 10:15 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum