Imar wrote:
> I don't think that eval is the fastest solution, though.
For those interested, I made a little test to check out the performace of
eval.
It would appear that the speed of the following two calls in Internet
Explorer (5.5) are pratically identical:
nTemp = document.myForm("myInput1").value ;
and
nTemp = document.myForm.myInput1.value ;
However the call :
nTemp = eval("document.myForm.myInput1.value") ;
in both Netscape (4.72) and IE took about twice as long. That said, both are
very quick (< milisecond on my machine) - so unless the javascript is
extremely intensive using the eval method should not pose a problem.
Cheers Imar for making the comment - I didn't think eval would be as great a
performance hit as that (hmm... I have some scripts to relook!).
For those interested the script used is copied below (you need a form with
two inputs).
Anil
Sevina Technologies
www.Sevina.com
function onLoad()
{
var i
var dAfter ;
var dBefore ;
var nTimeOfNonEvalTest ;
var nTimeOfEvalTest ;
var nTemp ;
dBefore = new Date();
for(i=0; i<10000; i++)
{
nTemp = document.myForm("myInput1").value ;
nTemp = document.myForm("myInput2").value ;
}
dAfter = new Date();
nTimeOfNonEvalTest = dAfter - dBefore ;
dBefore = new Date();
for(i=0; i<10000; i++)
{
nTemp = eval("document.myForm.myInput1.value") ;
nTemp = eval("document.myForm.myInput2.value") ;
}
dAfter = new Date();
nTimeOfEvalTest = dAfter - dBefore ;
alert("Non-Eval: " + nTimeOfNonEvalTest + "\n" + " Eval :" +
nTimeOfEvalTest) ;
}