473,516 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eval, alternative

Hi,

As you can see from the following code, I am trying to manipulate a
large number of layers. I have read many times in the past how the
"Eval" function should be used very sparingly as it can make code run
slowly. The following works fine on my PC, however I do not know what
will happen on other platforms, so is there an alternative to "Eval"
in this instance.

for(var i=1;i<505;i++){
eval('document.all.mun'+ i +'.style.visibility=\'hidden\'')
}

I have experimented with the following but cannot get it to work

document.all.mun[i].style.visibility='hidden'
Nov 11 '08 #1
4 2109
sp****@corbetteer.co.uk wrote:
Hi,

As you can see from the following code, I am trying to manipulate a
large number of layers. I have read many times in the past how the
"Eval" function should be used very sparingly as it can make code run
slowly. The following works fine on my PC, however I do not know what
will happen on other platforms, so is there an alternative to "Eval"
in this instance.

for(var i=1;i<505;i++){
eval('document.all.mun'+ i +'.style.visibility=\'hidden\'')
}

I have experimented with the following but cannot get it to work

document.all.mun[i].style.visibility='hidden'
var found=document.getElementById("mun"+i);
if(found)
found.style.visibility="hidden";

This makes it compatible with other platforms too, by avoiding
document.all usage.
Nov 11 '08 #2
On 11 Nov, 14:57, Stevo <n...@mail.invalidwrote:
spa...@corbetteer.co.uk wrote:
Hi,
As you can see from the following code, I am trying to manipulate a
large number of layers. I have read many times in the past how the
"Eval" function should be used very sparingly as it can make code run
slowly. The following works fine on my PC, however I do not know what
will happen on other platforms, so is there an alternative to "Eval"
in this instance.
for(var i=1;i<505;i++){
* * * * eval('document.all.mun'+ i +'.style.visibility=\'hidden\'')
}
I have experimented with the following but cannot get it to work
document.all.mun[i].style.visibility='hidden'

var found=document.getElementById("mun"+i);
if(found)
* *found.style.visibility="hidden";

This makes it compatible with other platforms too, by avoiding
document.all usage.- Hide quoted text -

- Show quoted text -
many thanks, works well!
Nov 11 '08 #3
sp****@corbetteer.co.uk writes:
I have read many times in the past how the
"Eval" function should be used very sparingly as it can make code run
slowly.
Indeed. Eval is evil, both for performance and maintainability.
The faster the javascript engines get, the more performance optimizations
they use, and an eval in the same scope means that you can kiss any static
analysis goodbye.
The following works fine on my PC, however I do not know what
will happen on other platforms, so is there an alternative to "Eval"
in this instance.
It will work the same if run in the same browser :)
for(var i=1;i<505;i++){
eval('document.all.mun'+ i +'.style.visibility=\'hidden\'')
Stevo already told you what to do to avoid both eval and document.all.
Just for the record, the way to avoid eval alone (which generalizes
to all other computed property names) is square bracket notation:
document.all["mun"+i].style.visibility='hidden';
/L
--
Lasse Reichstein Holst Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Nov 11 '08 #4
In comp.lang.javascript message <095992ad-f590-4f7d-8545-2ff82922a2b1@t3
9g2000prh.googlegroups.com>, Tue, 11 Nov 2008 06:45:06,
sp****@corbetteer.co.uk posted:
>
document.all.mun[i].style.visibility='hidden'
You already have a better answer; but what you were attempting is more
likely to be achieved by something like

document.all["mun"+i].style.visibility='hidden'

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
Nov 11 '08 #5

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

Similar topics

9
8453
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select values, this one is a simplified version where its passed. function checkIt(selVal){ valueInDec1 = eval(selVal); //do some calculations here...
9
1851
by: Mike | last post by:
After reading much on the evils of eval, I have a question using my own personal use of the function... We have a reports system that will generate reports based on a number of parameters available on a blotter at the top of our report system. Each report could (and does) use a combination of some (but not all) of these 15 parameters. ...
7
2258
by: steveneill | last post by:
Is this an alternative to eval(). Admittidly, I have done *very* little testing (ran it a few times in Firefox), but it seemed to work suprisingly well with simple expressions such as "alert('hello')" function _eval(s) { var h = document.getElementsByTagName("HEAD"); var o = document.createElement("SCRIPT"); o.text = s; h.appendChild(o);
1
1659
by: Newish | last post by:
Hi Is it really not recommended to us Eval in databound controls as follows: <td><asp:TextBox id="BookTitle" Runat="Server" Text='<%# Eval("BookTitle") %>' Font-Size="8pt" Width="80px"/></td> If so what is the alternative.
11
1968
by: C.W.Holeman II | last post by:
I am looking for an example using the object argument to eval(). http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:eval -- C.W.Holeman II | cwhii@Julian5Locals.com-5 http://JulianLocals.com/cwhii To only a fraction of the human race does God give the privilege of earning one's bread doing what one would have...
4
3369
by: Jon Slaughter | last post by:
I'm using eval to excute some mixed php and html code but I cannot debug it. I am essentially using filegetcontents to load up a php/html file and then inserting it into another php/html file and then using eval to execute the final product. If I were to use include and output buffering instead of filegetcontents would it allow be to...
7
1766
by: Ciaran | last post by:
Can someone please give me a hand with this? $arr=array(2,4,5,6); $test='arr'; echo (eval("$".$test."")); I'm trying to get it to echo 2
13
3155
by: My Pet Programmer | last post by:
The way I usually set up and work with the XMLHttpRequest to execute server side functions and get results is this: var url = "someurl?params=" + params; var conn = createRequest(); // gets an XMLHttpRequest object conn.open("GET", url); conn.onreadystatechange = function () { if (conn.readyState == 4 && conn.status == 200) {
10
494
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with the different types of objects you can create as values. I really don't like using eval, and it's causing problems, like if I do something like...
0
7276
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.