[thelist] Need help with Javascript...

Syed Zeeshan Haider szh at softhome.net
Thu Aug 1 16:16:01 CDT 2002


From: "Phil Essing" <essing at vdl2.com>
To: <thelist at lists.evolt.org>
Sent: July 31, 2002, Wednesday 11:41 PM
Subject: [thelist] Need help with Javascript...



> I'm trying to pass a value from one function to another, and I keep
> getting a "x is not an object" error.
>
> Here's a code fragment:
>
> // Populate the calendar
> for (j=vFirstDay; j<7; j++) {
> strDate = this.format_data(vDay);
> vCode = vCode + "<td><A HREF=\"javascript:fillForm('" + strDate
> + "');\">" + strdate + "</A></td>";
> vDay=vDay + 1;
> }
>
> This loop is only one part of the function that builds the vCode
> variable, which represents all the HTML for a calendar.  I'm trying to
> pass strDate to another function that parses the variable and then
> updates 3 separate form fields.  I do have an idea why I get the error
> (it's trying to send the value of strDate and not strDate itself), but
> have no idea how to solve the problem.
>
> Thx in advance for any guidance.

The problem is that when you create/declare a variable in a function
then it is not available out side the function in which it was
created/declared. So for using a variable in *multiple functions*
declare it outside all functions without assigning it any value. It can
be done by simply putting "var" before the variable name:
example:

var variableNameHere
function whatever(){
//your syntax goes here
//your syntax goes here
//your syntax goes here
}

The common trick for avoiding variable errors is to declare all
variables (which you are going to use in a certain JS chunk) right after
<script> tag. Example here:

<script type="JavaScript">
var put, allOf, your, variables, here, separated, with, commas, here,
like, I, have, done
//your other JS goes here
//your other JS goes here
//your other JS goes here
//your other JS goes here
</script>

Hope this helps.

Syed Zeeshan Haider.
http://syedzeeshanhaider.faithweb.com/




More information about the thelist mailing list