> I've always used it before to dynamically find the value of an object,
> such as:

> var fieldValue = eval("document.all."+fieldID+".value");

There is no need for this. Collection items can be accessed equally as
"collections.foo" or collections['foo']. So you can use the latter syntax:

  var fieldValue= document.all[fieldID].value;

For 99% of all scripts, there is no need to use eval(), and for robust,
readable scripting it's usually best avoided.

> But what about assigning values dynamically, the other
> way round?

> eval("document.all."+fieldID+".value") = "New value";

Again, the better syntax is:

  document.all[fieldID].value= 'New value';

but if you did do it with eval(), possibilities would be -

  eval('document.all.'+fieldID+'.value= "New value"');

  eval('document.all.'+fieldID).value= 'New value');

The former does the entire assignment through eval(), the latter uses
it to get a reference to the object, and then assigns to that object's
'value' property.

> This gives an error "Cannot assign to a function result".

This is a classic reference/value confusion, a really common problem
amongst the imperative programming languages in common use today, which
is made especially confusing in scripting languages that have constructs
like eval().

An assignment statement takes the form:

  (reference)= (value);

So, if you write:

  a= a;

The a on the right-hand-side has to be evaluated to get a value, say '3'.
The a on the left-hand-side, despite it being written exactly the same way,
stays a reference, because you can only assign things to a reference - it
doesn't make sense to say

  3= 3;

Anyway, the function eval() explicitly evaluates something, so you're left
with a value, not a reference. When you write this on the right-hand-side
of the assignment you don't notice the difference -

  a= a;
  a= eval('a');

These work the same and have the effect 'a= 3;'. However, put the eval()
on the other side:

  a= a;
  eval('a')= a;

These are now different. The second assignment tries to do '3= a;', which
cannot work.

value/reference confusions of various forms are the root of *lots* of bugs
in software in many languages often considerably more subtle. (Some
aspects of pure-OO or Functional programming could theoretically rid us of
the problem.)
and@doxdesk.com