home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

JavaScript Function Calling From, Multiple Instances/Locations

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2709
Discussions: 200,966, Posts: 2,379,635, Members: 246,332
Old June 17th, 2008, 06:57 PM   Digg it!   #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:
Code:
displayTimeInt()
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!
apollobc is offline   Reply With Quote
Old June 23rd, 2008, 07:50 PM     #2 (permalink)
Member
 
Join Date: Oct 2003
Posts: 263
header

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.
amtrac24 is offline   Reply With Quote
Old August 13th, 2008, 01:41 PM     #3 (permalink)
Junior Member
 
Join Date: Jun 2008
Location: Boulder City, NV
Posts: 2
Red face
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...
apollobc is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript function problem csamuels Webmastering and Programming 1 October 11th, 2006 03:35 PM
Collecting Certain File Types From Multiple Locations J1mmy General Tech Discussion 1 August 11th, 2006 08:30 PM
Toshiba laptop function keys won't function sparkle Technical Support 2 September 25th, 2004 04:20 PM
Javascript 'Imageswap' function fails... Kurylo General Tech Discussion 2 April 23rd, 2002 06:12 PM
Javascript 'Imageswap' function fails... Kurylo General Tech Discussion 5 April 22nd, 2002 06:36 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3012)
Forty-six years ago today (7)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Internet Lost (5)
windows 7 problem (7)
windows vista security holes (15)
Point and Shoot Camera Suggestions. (6)
Is the PSU I received dead? (13)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Recent Discussions
windows vista security holes (15)
Help getting around port 80 for camer.. (4)
Laptop with wireless problem. (12)
Open With ..... Win7 (2)
Internet Lost (5)
Skillsoft Network+ Study Software Que.. (9)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Nvidia GTX 260 problem (1)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)


All times are GMT -4. The time now is 02:37 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28