[thelist] Javascript Eval Help....

.jeff jeff at members.evolt.org
Tue Jul 23 20:43:01 CDT 2002


anthony,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Anthony Baratta
>
> I can't see my error....
>
> I'm gettting an error with this line:
>
>     eval('document.FormOOS.prod' + x + 'Subtotal.value') =
>          parseInt(eval('document.FormOOS.prod' + x + 'Qty.value')) *
>          parseFloat(eval('document.FormOOS.unitPrice' + x + '.value'));
>
> The error is:
>
>     Error: invalid assignment left-hand side
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

look closer.  the error message you're getting is actually telling you what the problem is.  in human terms, it's saying you can't have an eval() on the left side of the assignment operator (=).

the answer is to wrap the entire statement with another eval().

<sound type="tires" value="screeching" />

whoa!

hold up!

first, for every eval() in that function, hit your head with that big, fat js reference book i *know* you keep handy.  when you're done, come back and finish this email.

you don't need to use the eval() method at all.  use the elements array to access those dynamically named form elements.

like this:

document.FormOOS.elements['prod' + x + 'Subtotal'].value;

make sense?

not only will the error go away, but the code will be imminently more readable and you won't be unnecessarily using up client-side horsepower.

now go take two advil for that headache.

;p

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list