[Javascript] Form focus

Nick Fitzsimons nick at nickfitz.co.uk
Tue May 11 03:24:06 CDT 2004


On 10/5/04 8:19 pm, "Mike Dougherty" <mdougherty at pbp.com> wrote:

<snip />
> If javascript arrays can be stored in the application scope of an ASP
> environment,

No, JScript arrays shouldn't be stored in Application scope within ASP. In
my experience, their contents tend to vanish when you try.

<snip />
> example:  I'm working on a menu system that uses the xmlhttp example provided
> by Hakan Magnusson
> on 5/5/04 to retrieve sub menu items from a menu server applet given a node in
> the menu tree.  The
> menu data will come from SQL, but that lookup is a fairly expensive process
> which could be 
> repeated frequently by each visitor.  If the menu server applet could store
> the results (as 
> assemled, returnable HTML) the cache could serve the string much more
> efficiently than going to
> the database for the same content.

If you're storing HTML, use MSXML2.FreeThreadedDOMDocument.x.0 (where "x" is
the version installed on the server - 3 or 4 last time I was doing this).
This is thread-safe for storage in Application scope. You can then use the
standard DOM methods (or, indeed, the Microsoft-only extensions) to create
and later extract the parts of the HTML you need. Something like this in
Application_OnStart (within global.asa):

// code starts
   var document = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0");
   // code here to get your info from the database
   // and put it into the DOMDocument as a list
   // e.g <ul><li id="first">First</li>...</ul>
   var listItem;
   listItem = document.createElement("li");
   listItem.setAttribute("id", "first");

   var list = document.createElement("ul");
   list.appendChild(listItem);
   document.documentElement = list;

   Application("someNavigation") = document;
// code ends

And then use it with something like:

// code starts
   var neededNode =
Application("someNavigation").documentElement.selectSingleNode("/ul/li[@id="
+ requiredId + "]");
   Response.Write(neededNode.xml);
// code ends

Note that in that first part, you want to use DOM methods to build the HTML;
you could build a string and use the "loadXML" method, but:
A) every time you make an error in forming the XHTML, it won't load;
B) it won't be as efficient as simply using createElement and so forth.

If you need any more help, I could dig out some working code later today;
let me know. (If all this is completely incomprehensible, also let me know;
I'm sure I could explain it better, but I haven't had much sleep :-)

HTH,

Nick Fitzsimons
-- 
Email: nick at nickfitz.co.uk




More information about the Javascript mailing list