Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error with included script

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I am working on a website that is mainly centered around ssi, so that I can easily change the interface and look of the website by only changing 3 files. I have one file for the navagation/bottom of the page, one for top, and one for the styles/javascript.

the format for one of my pages goes something like this:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>Robs Gadget Corner</title>
<!--#include file=&quot;styles.txt&quot;-->
</head>
<body bgcolor=&quot;#359EFF&quot; background=&quot;images/backgroundgrid.gif&quot; text=&quot;#086C08&quot;>
<!--#include file=&quot;top.txt&quot;-->

 <!--this is where the content goes-->
<!--#include file=&quot;bottom.txt&quot;-->
</body>
</html>

anyway, I have some js code in the bottom.txt file that prints out the navagation from an array. The reason that I dont have it just written in html is I wanted to have the link to the page the user is on to be highlighted. The code works fine on all pages except one, which I get an error that says 'object does not support this property or method'

here is the code (with line highlited in red)

Code:
<script language=javascript>

//**--this first large block of code is just an array with the different links and images
Code:
var preLinkArray=new Array('<a href=\&quot;index.shtml\&quot; class=\&quot;linkTypeA\&quot;>Home</a><br>','<a href=\&quot;computers.shtml\&quot; class=\&quot;linkTypeA\&quot;>Computers:</a><br>','<a href=\&quot;pranks.shtml\&quot; class=\&quot;linkTypeA&quot;>  <img border=0 src=images/bullet.gif align=absmiddle>Pranks</a><br>','  <a href=\&quot;secrets.shtml\&quot; class=\&quot;linkTypeA&quot;><img border=0 src=images/bullet.gif align=absmiddle>Secrets</a><br>','  <a href=\&quot;links.shtml\&quot; class=\&quot;linkTypeA&quot;><img border=0 src=images/bullet.gif align=absmiddle>Links</a><br><br>');

//**--this function reads in the above array, and through some fancy string manipulation, makes four more arrays, each with part of a link in it (the href, the text, the opener tag, the closing tag)
Code:
function lnkAryObj(links){
this.num=links.length;
this.preText=new Array();
this.endText=new Array();
this.linkText=new Array();
this.href=new Array();
for (i=0;i<links.length;i++){
link=links[i];

//this is a verry condensed algorithim, so it is also very confusing!

start=link.substring(0,link.indexOf('class=&quot;linkTypeA&quot;>')+18);
end=link.substring(link.indexOf('</a>'),link.length);
middle=link.substring(link.indexOf('class=&quot;linkTypeA&quot;>')+18,link.indexOf('</a>'));
choppedstart=start.substring(start.indexOf('href='),start.length);
beginingofhref=choppedstart.indexOf('&quot;')+1;
Code:
choppedstart=choppedstart.substring(beginingofhref,choppedstart.length);
Code:
endofhref=choppedstart.indexOf('&quot;');
href=choppedstart.substring(0,endofhref)
this.preText[i]=start; this.endText[i]=end; this.linkText[i]=middle; this.href[i]=href;
}
return this
}

//**--all this next function does is print out the link table, with the correct link as just text
Code:
function printLinks(links){
pageLocation=location.href
pageLocation=pageLocation.substring(pageLocation.lastIndexOf('/')+1,pageLocation.length);
if (pageLocation==''){pageLocation='index.shtml'}
for (i=0;i<links.num;i++){
if (pageLocation!=links.href[i]){
document.write(links.preText[i]+links.linkText[i]+links.endText[i]);
} else {document.write(links.linkText[i]+'<br>');}
}}

//**--the function calls
Code:
var linkObj=new lnkAryObj(preLinkArray);
printLinks(linkObj);

</script>


theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Eclipse,

Well I would not usually post this type of response, but I know you have been around a while and seem sincere.

> I have some js code in the bottom.txt file that prints out the navagation
> from an array. The reason that I dont have it just written in html is I wanted
> to have the link to the page the user is on to be highlighted.

If that is the problem your code is attempting to solve then I would say the solution is overly complex. Complex code is always more error prone than simple code. Therefore simple problems should be solved with simple designs.

&quot;But, that's just my opinion... I could be wrong&quot;.
-pete
 
hmm, good point palbano, but I cannot think of any other way to do what I need. If you don't yet know what I would like to do, here it is:

I have a navagation bar on the right of my page. It has most of the pages in my site listed. simmilar to .

When you click on a link on the nav bar, you go to that page (duh), but then on the new page, the link becomes just text, not a link.

have any ideas?

oh, remember I need to have the navagation bar be included.

theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
- i would say choppedstart might be empty some times : alert start, beginingofhref, and even choppedstart and see what it says
- palbano's right, i'm sure there are much simplier ways of doing that. For instance i would use a parameter to tell me on which page i'm actually, and while displaying links, if the link's id matches the parameter for the page i'm on, then don't add the a tag (or do href=void())
 
well, I think that would make things easier, but not really, because the url's that I am disecting are the actual links, not the location of the current page.

and what's href=void()



theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
&quot;the url's that I am disecting are the actual links, not the location of the current page.&quot; --> in my case this doesn't change anything, as the parameter is whatever you want - the heavy cost is that you have to update all of your links (so as to pass the parameter !)
a href=&quot;void()&quot; does nothing, just like a href=&quot;#&quot; ... that was to say, when your link's id matches the parameter you passed, then don't display as a link or use a &quot;false&quot; link
sorry my english is crappppp today
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top