home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2853
Discussions: 188,380, Posts: 2,243,462, Members: 232,608
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: 255
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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

Most Active Discussions
Is It Just Me? (2885)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Help with an Ati Radeon HD 4850 512.. (25)
Recent Discussions
Building a gaming computer advi.. (0)
Best digital camera for under 2.. (14)
Help with an Ati Radeon HD 4850.. (25)
Install Problem for Windows Def.. (0)
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Laptop waking up itself (0)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:43 PM.
TechIMO Copyright 2008 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