473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Can't Return any values from Functions

Hi guys,

I can't seem to get anything returned from functions.

If I use the <script src = ... > command, nothing works. But if I
define the functions locally within the file, then it works.

Something simple:

function abc() { return 99; }

If I tried to access this function by placing it inside a .js file,
and then including it, it returns "undefined". Everything else works
except for returned values...

If I define this function locally, it returns correctly the value of
99.

What is going on?? This is so weird.

Zhichun
Jul 20 '05 #1
2 1859
Zhichun Pu wrote:
Hi guys,

I can't seem to get anything returned from functions.

If I use the <script src = ... > command, nothing works. But if I
define the functions locally within the file, then it works.

Something simple:

function abc() { return 99; }

If I tried to access this function by placing it inside a .js file,
and then including it, it returns "undefined". Everything else works
except for returned values...

If I define this function locally, it returns correctly the value of
99.

What is going on?? This is so weird.

Zhichun


Without more information it's hard to know what the problem is. However,
one mistake some people make is to include <script></script> tags in
their external .js file. The .js file should only contain JavaScript, it
should contain no HTML tags or comments.

So if your inline code is:

<script type="text/javascript">
<!--
function abc() { return 99; }
//-->
</script>

Then the external .js file should contain only:

function abc() { return 99; }

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
I tried writing a few more test scripts and they all worked.... maybe
it was the script I was using that didn't work.

function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else {
if( document.documentElement &&
( document.documentElement.clientWidth ||
document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else {
if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
}
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}

I pulled it off a website. It's supposed to get the width and height
of a browser's window. I just did "return [myWidth, myHeight];" and it
didn't work. I tried to return a single value and that didn't work
either.

Maybe it also had to do with the DynAPI package I was using?
Javascript has changed so much since I last programmed in it....

Any comments + ideas would be greatly appreciated. Thanks to all those
who tried to help =)

Zhichun

sc*******@hotmail.com (Zhichun Pu) wrote in message news:<e8*************************@posting.google.c om>...
Hi guys,

I can't seem to get anything returned from functions.

If I use the <script src = ... > command, nothing works. But if I
define the functions locally within the file, then it works.

Something simple:

function abc() { return 99; }

If I tried to access this function by placing it inside a .js file,
and then including it, it returns "undefined". Everything else works
except for returned values...

If I define this function locally, it returns correctly the value of
99.

What is going on?? This is so weird.

Zhichun

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
0
by: Mujdat Pakkan | last post by:
We have an interesting case where we want to use Postgres both as a database and a front end to a proprietary database. For the latter, we wrote functions that access the proprietary database. Then...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
4
by: BinWang85 | last post by:
The following is the code: #include <iostream.h> #include <math.h> //needed for decimal calculations int main() { int employee_num; double FetchHours(void);
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
4
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.