473,398 Members | 2,368 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,398 software developers and data experts.

Saving/caching state between function calls

Hi,

I'm a beginner to DHTML. I have a javascript function that gets called
a lot from buttons etc within an html file. The first thing this
function does is a "document.getElementsById" call which I'm assuming
could be pretty expensive.

My question is could this information be cached, so the
getElementsById only gets called once? I was thinking of simply using
a global variable initialized to null and assigning it at the first
call, but I dont know if the standard supports this, or if the js
"environment" gets reset at every function call from the body (so that
each call works as if it were the first), or if the standard is
unclear on this, etc.

I'd appreciate any alternative solutions if the above is not going to
work (I'm not looking for hard-disk type storage like cookies, or any
nonstandard solutions: not worth the effort!). Thank you.

Khan

Feb 28 '07 #1
1 1191
Hi Khan,

Me too!

The docs I've seen (for VAR I think) say if they are declared outside of a
function then they are global to all functions and won't be collected when
the function exits. But I couldn't get 'em to work; XXX is null or not an
object :-(

Where to put 'em and what state/when are they instantiated? Couldn't find an
example.

Like you I want to getElementById (in my case the Applet) only once.

Cheers Richard Maher

<ch*****@my-deja.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
Hi,

I'm a beginner to DHTML. I have a javascript function that gets called
a lot from buttons etc within an html file. The first thing this
function does is a "document.getElementsById" call which I'm assuming
could be pretty expensive.

My question is could this information be cached, so the
getElementsById only gets called once? I was thinking of simply using
a global variable initialized to null and assigning it at the first
call, but I dont know if the standard supports this, or if the js
"environment" gets reset at every function call from the body (so that
each call works as if it were the first), or if the standard is
unclear on this, etc.

I'd appreciate any alternative solutions if the above is not going to
work (I'm not looking for hard-disk type storage like cookies, or any
nonstandard solutions: not worth the effort!). Thank you.

Khan

Feb 28 '07 #2

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

Similar topics

1
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, User can adjust the size of columns of a table or the position of splitter in UI. We want these adjustments to be remembered when we restart the application. Currently, we are saving these...
6
by: Hypo | last post by:
Im relatilvly new to a web programming in general, and here's the situation i have: I have a default page with dynamic content, and one button with onclick code something like this: { // do...
2
by: Slugsie | last post by:
I am writing a .Net web application that needs to save some state information across web pages. I'm using Session.Item("<item name>") = <item state> calls in my VB code so save the session...
2
by: Joel Barsotti | last post by:
My website has different products and I've developed a nice little object oreinted class library for them. I then use the objects for products and such on many different pages. Especially with...
0
by: jason | last post by:
hi experts, support.microsoft.com/kb/917072 and http://msdn.microsoft.com/msdnmag/issues/06/07/WebAppFollies/ As pointed out in these articles, users might get session variables belong to...
3
by: Gary W. Smith | last post by:
I had a couple questions about data caching. We have a site that gets a huge amount of traffic to a few specific pages that have a lot of data on them (300k hits/hour during peak, about 6-10 data...
1
by: mwk24 | last post by:
Hi all, I have standard AJAX script that calls a php file to load the latest information and uses xmlHTTP.responseText to write it to innerHTML of a div by id. It works fine on IE/firefox, but I'm...
1
by: mwk24 | last post by:
Hi all, I have standard AJAX script that calls a php file to load the latest information and uses xmlHTTP.responseText to write it to innerHTML of a div by id. It works fine on IE/firefox, but I'm...
5
by: =?Utf-8?B?TWFyaw==?= | last post by:
I'm researching what is the best way to create a generic WCF proxy wrapper that has the following requirements: 1. Remove the System.ServiceModel config section requirement for clients. We have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.