[Javascript] New to JavaScript, trouble w/ first prog

Peter-Paul Koch gassinaumasis at hotmail.com
Sun Mar 24 04:48:40 CST 2002



>Hello Javascript List,
>I'm a newbie javascript programmer. I'm just now learning the ways of the 
>script. I'm having trouble understanding how or what order variables seem 
>to be initialized in.

In the order they appear in the source code or in the order they're called 
(in case of local variables in functions).

>I'm also having trouble with functions returning "NaN" and
>"undefined" but I'll tackle the first problem first.

NaN is a number and means that it's not a number. undefined means that a 
variable exists but doesn't have a value.

>In my program 'theForm'
>evaluates to [null]. I don't understand this. Why is it evaluating to 
> >[null]? It's right there in the beginning of the program. It should 
> >contain document.forms[0] shouldn't it?

document.forms[0] is only available *when the page has been loaded 
completely*, so you should call your script onLoad.

After that I've also got my functions
>evaluateFica() and evaluateMed() evaluating to NaN and evaluateFed() and
>evaluateSta() evaluating to undefined. Don't quite understand the 
>precedence
>going on here, can someone shed some light? I thought the code seemed 
>pretty
>straight forward I don't know what I'm missing.
>Peace,
>an eager newbie  Aaron
>
>Here is my program code:
>
><!-- Hide from mail client
>
><html>
><head>
><title>Cheque Evaluator</title>
><script language="JavaScript">
>var gross
>var theForm = document.forms[0]

You can't define theForm here, it hasn't yet been loaded.

>function evaluateFica() {
>var evalu = eval(gross * 0.067)
>return evalu}

You don't need eval here, you can just do

return gross * 0.067


ppk

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




More information about the Javascript mailing list