June 17th, 2008, 06:57 PM
|
#1 (permalink)
| | Junior Member
Join Date: Jun 2008 Location: Boulder City, NV
Posts: 2
| JavaScript Function Calling From, Multiple Instances/Locations Being somewhat, new to javascript coding, I am not sure why I am having the following issues? I have a javascript with several functions in it called 'ajax.js'. It is called in the body tag. Code: <body onload="javascript:loadData();Fadewl();SLIDES.play();> In the 'ajax.js' the "loadData()" function is: Code: function loadData() {
updateBanner();
updatePlaying();
updateHistory();
updateOnline();
updateListeners();
displayTimeInt();
updateTime();
Fadewl();
} The first problem I am having is that if a function in the 'ajax.js' script is not called, or unused, I get an "Error on page" message in the browse status bar? The second problem I am having is that I can only us the function output in one place, I can not call it from multiple locations? An example is the function that displays the time is: and the output is shown by the HTML code: Code: <span id="disTime"> I can only have this 'SPAN' tag in one location, on one page only? The third problem I am having is that, for example, the time is displayed from a "header file" and displays in all pages fine that are in the root directory. There are a couple of pages that call the "header file" from sub-directories and in that case the: Code: <span id="disTime"> is empty and displays 'blank', the time is missing? Thanks for any help! |
| |
June 23rd, 2008, 07:50 PM
|
#2 (permalink)
| | Member
Join Date: Oct 2003
Posts: 255
|
Problem 1: I would like to see the header syntax:
It should be something like <script type="text/javascript" src="form. js">
I would make sure the path to the js form is correct and it can see the file.
Thus try putting the ajax. js is the same directory as the .html to first test to make sure your code works. Then you can play around with where the js file resides.
Problem 2: It would help if I can see how you have displayTimeInt setup.
You should only have 1 item on the page with that specific ID.
<span id="disTime">
<span id="disTime2">
would be fine. Just make sure you change the id.
Otherwise you can have the following which is ok but not suggested. Then you would call the element by name instead of by id in javascript. I highly suggest you don't do this. I have seen it done in another app and it worked. Not sure if IE 7 will error out..This was back in IE 6 days
<span id="disTime" name="TheTime">
<span id="disTime" name="TheTimeOnBottomPage">
Problem 3:
It can't find the function so the function is never ran. Thus the time is blank because it never got populated by the function. You need to modify the header to make sure it can see the function. |
| |
August 13th, 2008, 01:41 PM
|
#3 (permalink)
| | Junior Member
Join Date: Jun 2008 Location: Boulder City, NV
Posts: 2
| Reply To amtrac24
Not sure why it has taken this long to get back to this.... Sorry
RE: Problem 1 Header Code (located in a subdirectory) Code: <head>
<meta http-equiv="Content-Language" content="<?=META_HTTP_LANG?>">
<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta http-equiv="EXPIRES" content="-1">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="description" content="<?=META_DESC?>">
<meta name="keywords" content="<?=META_KEYWORDS?>">
<title><?=META_HTTP_TITLE?></title>
<link rel="shortcut icon" href="/favicon.ico">
<link type="text/css" rel="stylesheet" href="<?=$bkgnd_path?>style.css">
<? #----- JavaScript Routines -----# ?>
<? if($user_java == TRUE){ ?>
<? include_once($_SERVER["DOCUMENT_ROOT"].'/user.javascript.php'); ?>
<? } ?> The last two lines convert out to: Code: $_SERVER["DOCUMENT_ROOT/inc/js/ajax.js The code works fine in the index page, where all the calls in function loadData() are used, but creates the JS error message on other pages where the functions are not used!
RE: Problem 2 function displayTimeInt() Code: function displayTimeInt() {
displayTime(1,'disTime');
/*displayTime(1,'disTime2'); ??*/
setInterval("displayTime(1,'disTime')",1000);
/*setInterval("displayTime(1,'disTime2')",1000); ??*/
} Not sure if that is what you ment about different IDs
RE: Problem 3 subdirectory paths
When the header file is being included in a subdirectory it must be loosing the correct path!
Since, I have basically no JS/Ajax programming, I am amazed that all of the functions work as expected! Well except for the problem mentioned previously! I am going to become 'oop' minded if it kills me.
Thanks... |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |