Change value in included file

Bob Stone
Bob Stone used Ask the Experts™
I have a bit of script that makes a mootools based menu item stay open

<SCRIPT type="text/javascript">
     var myMenu = new ImageMenu($$('#kwick .kwick'),{openWidth:220, start:0});

The ", start:x" bit identifies the correct tab, 0 for Home page, 1 for About Us, 2 for Portfolio page, etc.

The menu is on the head.htm that is included in every other page, I tried to move the above onto the page with the SSI but that makes it slow and causes problems.

How to I change the value of start: x from each page?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can't edit the include file from a web page that uses the include file, it doesn't have permissions.  You could change it from a PHP or server page.  But it is easier to do it manually then upload it.

If you want to do this interactively, the only way to do it would be to write the include file with javascript, then have the javascript change the parameters based on some run-time criterion.


Seems like it would be possible to make the X in "start:x" a variable in the include file, then give it a fixed numerical value in the subsequent file(s) that call the include. I am just not clear on how to do that exactly.
In general, variables should be contained in the main HTML page for javascript in that page to manipulate them.  However, you COULD put a variable in an include file and also do the manipulation in an included javascript file.  That is stretching the reliability of includes, but it IS possible.  Before I go to great lengths to explain how to do this, please address these --

1.  does your server work correctly for including the include file in all pages that use it?
2.  What is the variable in the include file that HAS to be in it, and where in the body is it located?
3.  What is the reason it could not be put in the page directly, rather than in an include file?
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


1. yes

The ", start:x" bit identifies the correct tab, 0 for Home page, 1 for About Us, 2 for Portfolio page, etc.
3. it reacts slowly and is jerky sometimes
Well, that doesn't really help much, so here goes --

Put your javascript include file as -- <SCRIPT src="included.js"></SCRIPT>
Put this link to that file at the END of the HTML file just before the </BODY> tag.
The reason is, it will run after the page has loaded, including the include data

and you have the way to include in the HTML file.

In the javascript file, you address the variables in the page as if they were IN the page, not in the include file.  And Remember, each of these variables MUST be in a tag something like a <SPAN> tag with an ID, so you can change it, example --

<SPAN id="var_x">var_x</SPAN>

document.getElementByID ("var_x").value = "my new value";

and you can manipulate the variable as long as it is enclosed with a tag that has an ID you can reach.

Of course the JS code can be in the file, but if you want this to work across many pages, use an included JS file, just as you would include HTML in the body.
I streamlined the code in the header file and left the bit in the file with the SSI includes and it works great now.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial