Jemminger,
You are right using with does make things slightly slower but I found that sometimes it is good to have such options available to you in two cases.
In a rare scenario where you have hundreds of form items to be redirected using this system the amount of text being sent could be much smaller if with() is used. I'll admit that it only happened to me once that with() was useful for that reason to me and the circumstances were really not working in my favor (400 form items on a web application and using server side zlib compression was out of the question because of a bug with Real Media Player and Windows).
I have used it a few times because I was lazy and didn't want to type too much (if I have to type the thing more than ten times I use with() unless speed of execution is primordial).
using Phoenix
using with() : 1161 milliseconds
without with() : 1042 milliseconds
using Internet Exploder
using with() : 400 milliseconds
without with() : 400 milliseconds
using Mozilla (latest build)
using with() : 1151 milliseconds
without with() : 952 milliseconds
Using Opera 7
using with() : 231 milliseconds (wow!!!)
without with() : 200 milliseconds (wow!!!)
I have to admit I am really impressed with the raw speed of Opera here! More power to Opera users!
This is the code I used to do the tests. Each test was run 5 times and I took the lowest number for each browser.
<html>
<head>
<title>Form element referencing using with()</title>
</head>
<body>
<form name="myForm">
<input type="text" id="myInput" value="let's test this baby">
<input type="button" value="test using with()" onclick="test1()">
<input type="button" value="test using direct path" onclick="test2()">
</form>
<script>
var iterations = 5000;
function test1()
{
var start = new Date();
for (var i = 0; i < iterations; i++)
{
with (document.myForm.myInput)
{
value = "testing";
}
}
var end = new Date();
document.myForm.myInput.value = end.getTime() - start.getTime();
}
function test2()
{
var start = new Date();
for (var i = 0; i < iterations; i++)
{
document.myForm.myInput.value = "testing";
}
var end = new Date();
document.myForm.myInput.value = end.getTime() - start.getTime();
}
</script>
</body>
</html> Gary
Haran