Access to variables within script

Results 1 to 2 of 2

Thread: Access to variables within script

  1. #1
    Join Date
    Dec 1969

    Default Access to variables within script

    Within the &#060;head&#062; section of my asp page, I write a subset of data from my database to a client side array within a &#060;script&#062;<BR>This takes place at the top of the script, which i envisage to be the area where variables should be considered &#039;global&#039;...beneath this section, but still within the same script, I have a series of subs. I call these subs from the main body of the page. But for some reason, within the subprograms, the &#039;global&#039; array cannot be accessed. In saying that, I mean that suppose myarray(1) contains a value of "me", my sub believes it has a null value. <BR><BR>I have taken the asp part out and manually filled the array, still keeping the same layout, and the subs have no problem accessing the array...but as soon as i introduce asp to the page, this null concept comes into play...<BR><BR>Could anybody help me out on why it is doing this? And/or how I can give my procedures access to this array. Perhaps I am not declaring the variable properly and need to explicity state its scope????<BR><BR>Thanks,<BR>confused :!

  2. #2
    Join Date
    Dec 1969

    Default Have you tried....

    ...showing us your code???<BR><BR>If so, where?<BR><BR>I would *GUESS* that the problem is that you haven&#039;t DIM&#039;ed the array before you encounter the SUBs. <BR><BR>Oh! Wait a minute!<BR><BR>Are you mixing <BR><BR>&#060;SCRIPT Language=VBScript RunAt=Server&#062;<BR>...<BR>&#060;/SCRIPT&#062;<BR><BR>and <BR><BR>&#060;%<BR>...<BR>%&#062;<BR><BR>code???<B R><BR>*THAT* can cause this problem if you aren&#039;t extremely careful!<BR><BR>*******<BR><BR>Incidentally, I like to discourage people from putting any kind of code in the &#060;HEAD&#062; unless they need to.<BR><BR>If you put code into the &#060;BODY&#062;, then it&#039;s much easier to debug (by putting Response.Write from ASP code and document.write from client-side JS code).<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts