Click to See Complete Forum and Search --> : editing a script so I can call it once for multiple pages


neiljabba
09-13-2003, 06:27 AM
I have the following script from javascriptsource that I need to convert so I can load the script instead of having it embedded on the page.

I understand the principle but being new to javascript cant convert this to make it callable.

This is for a school site so help would be appreciated.

The full script is below including the body details it is unedited for my purposes but thats the bit I can do!!!

many thanks in advance

neiljabba@hotmail.com

<!-- TWO STEPS TO INSTALL DOUBLE MENU:

1. Copy the first coding into the HEAD of your HTML document
2. Add the second code into the BODY of your HTML document -->

<!-- STEP ONE: Add this code into the BODY of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--
v=false;
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript1.1">
<!--
if (typeof(Option)+"" != "undefined") v=true;
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

<!-- Original: webreference.com -->
<!-- Web Site: http://webreference.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
if(v){a=new Array();aln=0;}
function getFormNum (formName) {
formNum =-1;
for (i=0;i<document.forms.length;i++){
tempForm = document.forms[i];
if (formName == tempForm) {
formNum = i;
correctForm = tempForm;
break;
}
}
return formNum;
}
function jmp(formName,elementNum) {
getFormNum(formName);
if (formNum>=0) {
with (document.forms[formNum].elements[elementNum]) {
i=selectedIndex;
if (i>=0) location=options[i].value;
}
}
}
function O(txt,url) {
a[k]=new Option(txt,url);k++;
}
function relate(formName,elementNum,j) {
if(v) {
k=1;
if(j==0) { // default category item
a=new Array();
O("Pick Item --->","");
}

if(j==1) { // 1st category items
a=new Array();
O("Pick Item --->","");
O("Buttons","http://javascript.internet.com/buttons/");
O("Clocks","http://javascript.internet.com/clocks/");
O("Cookies","http://javascript.internet.com/cookies/");
O("Forms","http://javascript.internet.com/forms/");
O("Games","http://javascript.internet.com/games/");
O("Messages","http://javascript.internet.com/messages/");
O("Miscellaneous","http://javascript.internet.com/miscellaneous/");
O("Navigation","http://javascript.internet.com/navigation/");
O("Page Details","http://javascript.internet.com/page-details/");
O("Pass. Protec.","http://javascript.internet.com/passwords/");
O("Scrolls","http://javascript.internet.com/scrolls/");
O("User Details","http://javascript.internet.com/user-details/");
O("Table Of Contents","http://javascript.internet.com/toc.html");
}

if(j==2) { // 2nd category items
a=new Array();
O("Pick Item --->","");
O("How Do I...?","http://forums.internet.com/cgi-bin/WebX?13@^265342@.ee6b7af");
O("Script Help","http://forums.internet.com/cgi-bin/WebX?13@^265342@.ee6b7ab");
O("Script Requests","http://forums.internet.com/cgi-bin/WebX?13@^265342@.ee6b7ad");
O("Intro to JavaScript","http://forums.internet.com/cgi-bin/WebX?13@^265342@.ee6b7a7");
O("What's New?","http://forums.internet.com/cgi-bin/WebX?13@^265342@.ee6b7a9");
}

if(j==3) { // 3rd category items
a=new Array();
O("Pick Item --->","");
O("JS Question?","http://forums.internet.com/cgi-bin/WebX?14@^3027@.ee6b313");
O("JS Contribution","http://javascript.internet.com/contribute.html");
O("Site Comments","http://javascript.internet.com/contact-us.html");
O("Other ...","http://javascript.internet.com/feedback.html");
}

aln2=a.length;
getFormNum(formName);
if (formNum>=0) {
formNum = formNum + 1;
with (document.forms[formNum].elements[elementNum]) {
for (var i=options.length-1;i>0;i--) options[i]=null;
for (var i=1;i<aln2;i++) options[i-1]=a[i];
options[0].selected=true;
}
}
} else {
jmp(formName,elementNum);
}
}
// End -->
</SCRIPT>
</head>

<!-- STEP TWO: Put this code into the BODY of your HTML document -->

<BODY>

<center>
<table border=0>
<tr valign=top>
<TD align=center><form name=f1 method=post action="" onSubmit="return false;">
<select name=m1 onChange="relate(this.form,0,this.selectedIndex); document.f2.m2.focus();">
<option value="/">Pick Category --->
<option value="/">JavaScripts
<option value="/">Message Forum
<option value="/">Feedback Form
</select></form></td>

<td align=center> <b>then</b> </td>

<td><form name=f2 method=post action="" onsubmit="return false;">
<select name="m2" onchange="jmp(this.form,0)">
<option value="/">Pick Item --->

<!--

Put a blank item (like below) for the MAXIMUM
number of items in one of your categories.
i.e. If your "largest" menu contains 5 items,
include 5 blank lines here. For 10, include
10, and so on.

-->

<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">
<option value="/">

</select></form></td>

</tr>
</table>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 4.56 KB -->

96turnerri
09-13-2003, 07:32 AM
why do you want to make it callable and when do you want it called?

neiljabba
09-13-2003, 07:45 AM
Thanks for your prompt reply

I need to make it callable because it appears on a number of pages with the menu available on all pages. If one of the menu values changes then this would require me to change the other pages and over time this may be wuite a few it already is alot.

I need to call it onload really so that its available straight away

Cheers

96turnerri
09-13-2003, 10:10 AM
ok cool ive tried and tested two methods, unfortunatly i could get neither of them to work :( , i will keep trying as i could do with something like this for one of my sites, if i find anything ill let u know m8

Mr J
09-13-2003, 01:21 PM
You could have it written to the documents.


Please see example files in the zip