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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with javascript code

Status
Not open for further replies.

tmasterv

IS-IT--Management
Apr 24, 2009
9
Hi,

I am new to javascript and have the following code that is throwing a "Object not found" errors when I click on the hyperlinks. Here is the code:

<head>
<script type="text/javascript" src="ajaxnav.js"></script>
</head>
<body>

<a href="mailto:eek:mitted">
<img src="helpdesk.jpg" border="0"></a><br>

<table>
<tr>
<td valign=top width=300>
<H5>omitted</H5>
<a href="javascript:void(0)" onclick="open_url('page-1.html','my_site_content');">Announcement 1</a><br>
<a href="javascript:void(0)" onclick="open_url('page-2.html','my_site_content');">Announcement 2</a><br>
<a href="javascript:void(0)" onclick="open_url('page-3.html','my_site_content');">Announcement 3</a><br>
<a href="javascript:void(0)" onclick="open_url('page-4.html','my_site_content');">Announcement 4</a><br>
</td>
<td valign=top>
<div id="my_site_content">
</div>
</td>
</tr>
<table>
<tr>
<td valign=top width=300>
<br>
<H5>SMO Frequently Asked Questions (FAQ)</H5>
<a href="javascript:void(0)" onclick="open_url('page-1.html','my_site_content');">FAQ 1</a><br>
<a href="javascript:void(0)" onclick="open_url('page-2.html','my_site_content');">FAQ 2</a><br>
<a href="javascript:void(0)" onclick="open_url('page-3.html','my_site_content');">FAQ 3</a><br>
<a href="javascript:void(0)" onclick="open_url('page-4.html','my_site_content');">FAQ 4</a><br>

</td>
<td valign=top>
<div id="my_site_content">
</div>
</td>
</tr>
</table>
</body>

ajaxnav.js is located in the same as the above file. So are the html files you see referenced in the javascript.

Anybody have any suggestions?

Many thanks in advance!
 
EDIT: I meant to write "ajaxnav.js is located in the same *directory* as the file that has the javascript.

Thanks for your help!
 
Try this

Code:
<a href="javascript:void(0)" onclick="javascript:open_url('page-1.html','my_site_content');">Announcement 1</a><br>

make sure that "page-1.html" is in the current folder, otherwise, tell the function where the file is.
 
It is located in the current folder, which is why I am perplexed!

Any other thoughts?

Thanks
 
you spelled javascript wrong in your href tag

--- missing the "s" in script

:)

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
no you didn't, why on earth didn't i see it???

can you provide the source of your javascript file?


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Sure, here is ajaxnav.js:

var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
if (!xmlhttp){
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
}
@end @*/
 
sorry, here is all the code:

var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
if (!xmlhttp){
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
}
@end @*/

if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}

var please_wait = "Please wait...";

function open_url(url, targetId) {
if(!xmlhttp)return false;
var e=document.getElementById(targetId);if(!e)return false;
if(please_wait)e.innerHTML = please_wait;
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function() { response(url, e); }
try{
xmlhttp.send(null);
}catch(l){
while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
e.appendChild(document.createTextNode("request failed"));
}
}

function response(url, e) {
if(xmlhttp.readyState != 4)return;
var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " +

xmlhttp.status+" "+xmlhttp.statusText;
var d=document.createElement("div");
d.innerHTML=tmp;
setTimeout(function(){
while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
e.appendChild(d);
},10)
}
 
If I take all of your code and write it on a single page, it works, no problem (i.e. don't put the javascript in a separate page, rather hard-code it in the <head> within <script> tags)

Can you try that and see if it works? If it works for you, then your refernce to the js file is incorrect.

Also, if you run the page through Firefox and view the javascript error in "Tools -> Error Console", you'll get a better description of the error including the exact file it's occuring in and line number within that file....



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
I tried that and the error object expected error is gone, but it still can't load my links, which I guess means that my link paths are wrong. Very weird since the links are located in the same directory as this file!
 
try referencing the links by going back to the root: i.e. if the page-1.html / page-2.html...etc are in a folder called: /pages/things/page-1.html:

Code:
<a href="javascript:void(0)" onclick="open_url('[b]/pages/things/[/b]page-1.html','my_site_content');">Announcement 1</a><br>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
I think I am getting closer. Now the error message is:

Error: uncaught exception: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "file://///things/toddwebsite/default.html Line: 43"]

I checked the permissions and they are open...

Any thoughts?

Thanks again for all your help!
 
Never mind, I figured that error out. To all who contributed to this thread, many thank you's and have a great day!!
 
Never mind, I figured that error out. To all who contributed to this thread, many thank you's and have a great day!!

Can you post what the eventual solution was, helps others who may be having the same issue to find out how exactly you fixed it.

Thanks, and if I was of any help, you're welcome

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top