I'm having an issue with calling a function from a external linked JS file. The file is linked like so in the header of the page: - <script type="text/javascript" src="file.js"></script>
And the function that exists in the file.js is called from the body of the html page like so but its not working??? - <script>myfunction('test');</script>
-
20 3308
try - <script type="text/javascript">myfunction('test');</script>
if that fails too, have a look at the error console.
That didn't work, the error console is saying:
myfunction is not defined
But it is in the JS file!?
did you check writing (JS is case sensitive, so myfunction() and myFunction() are different)?
Yup, checked this and its all ok, its a stange one as its the way i've always called functions from an external JS file!?!
can you post a link to that file?
This is all thats in the file: - function myfunction(input) {
-
document.write(input);
-
}
are you sure the file is loaded correctly?
@Dormilich
Ahh! That's the point ;)
Actually what i think that when he calls the "function" then the JS file not loaded.
You better to keep your "this type of function(what you call inside HTML body)" in your script tag. -
<script>
-
//some function definitions
-
</script>
-
....
-
....
-
....
-
....
-
<script>/*call the function*/</script>
-
....
-
....
-
@dmjpro
this sure solves the problem, but you pay it with bandwidth traffic and download time (this is no problem when having only some very small functions, but if you need the benefits of larger libraries, this is not an option)
some background:
external JS files are treated similar to images, if the browser has this file cached (i.e. in its memory), it will only look if the server provides a newer file and only in that case the file is loaded again (relevant when you need a script on many pages)
Then first time it will not work.
And how can i make sure when i make this call then my external file gets loaded completely? ;)
@dmjpro
if you have access to the HTTP request (e.g. in FireBug*) you'll see a 404 status for that file. (200 for all OK, 304 for file not changed) @dmjpro
a simple test is - if (myfunction) alert("myfunction() exists");
* Firefox WebDev extension
@Dormilich
The code must be like this .. -
if(typeof myfunction!= 'undefined') //some code
-
Yeah i thought of this..If i need to call that "function" at that moment then ?
@dmjpro
throw an Exception* and quit. but usually there's no problem in including an external file**.
* seen at MDC
** especially if you manage to separate JS code from HTML. some handy functions for this are provided through the event handlers. further you can replace document.write() calls by DOM manipulation (createElement(), appendChild(), …).
Wouldn't -
window.onload = function ()
-
{
-
myfunction();
-
}
-
overcome that problem too?
Or calling it from <body onload="myfunction()">?
@Markus
I (personally) don't consider that as an option.
although the original problem is (I think) rather, whether the external file is loaded or not. otherwise I can't imagine what cause should be there for the error message.
@Markus
See "onLoad" event fired when page loaded completely. Now before getting loaded fully page needs to do something which will be by JavaScript that's where the context comes in ;)
What i saw in GMail ... basically the Mail ID box gets focus first then at "onLoad" the Password box gets focus.
@dmjpro
what advantage should that have? the password box is the first item to be used, I don't see a benefit for marking the ID box first (besides that you can mimic that with a little timeout).
@Markus
What you posted .. "ziycon" needs to execute some JS code before the page getting loaded fully but you suggested to execute this after the page loaded fully ;)
@Dormilich
Actually what i meant here .... before page loading fully Mail ID box gets focus and after page loaded fully the Password box gets focus. That's what i said .. Actually i am not against this policy, it should be .. Actually What "Markus" said, with respect to that post i gave an example.
May be some confusion created over here ;) sorry!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Scott Allen |
last post by:
Hello,
I'm new to C++ development and I'm trying out figure out the cause of
an 'unresolved external symbol' error that I'm receiving when
compiling. Here is some history on what I'm doing:
I...
|
by: Richard Hayden |
last post by:
Hi,
I have the following code:
/******************************** file1.c
#include <iostream>
extern void dummy();
inline int testfunc() {
|
by: Chuck Mendell |
last post by:
I am having problem with external javascripts. My OS is XP Pro. I am told to
create an external javascript using a .js extension. (I did that) The
external .js is very simple, containing:
...
|
by: keith |
last post by:
I created a class libery which has name space Assembly
and class Assembly and compiled it.
Then created a C# project and called a method in
the external class
e.g.
Assembly dll;...
|
by: Olivier Lechenne |
last post by:
I am converting some projects from VS 6.0 to VS .NET 2003 and I get a linker
error
error LNK2001: unresolved external symbol ___security_cookie or
error LNK2001: unresolved external symbol...
|
by: wingman |
last post by:
Hello All
I'm completely new to ASP.Net. I need to write a page to fetch an external
call
which actually call a Java program to download a file, the content of this
downloaded is...
|
by: Trapulo |
last post by:
I've a datarepeater that loads custom external templates with loadtemplate
and bind data to them. All ok.
Now I need to localize some text labels, but I don't know how can I change
this data. If I...
|
by: Dominic via DotNetMonster.com |
last post by:
I am a CA-OpenROAD programmer, but I attempting to build some VB.NET DLLs
and access them through OpenROAD as an external Windows TypeLib.
I have managed to build a simple DLL (code follows) but...
|
by: PrettySneaky |
last post by:
I have bumbed into a frustrating problem with my webservice. When I run
he web site in Visual studio 2005 everything works fine. But when i try
to publish it, it seems to be unable to call a method...
|
by: lookaround |
last post by:
Hi everyone,
I need some help...
I call an external exe (a command-line tool) with Process.Start through
this code:
try
{
p = new Process();
p.StartInfo.UseShellExecute = false;...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |