[UPHPU] javascript issue
Michael J. I. Jackson
mjijackson at gmail.com
Thu Nov 19 09:56:33 MST 2009
Hi Merrill,
a) Using eval is not a sin! If you believe that, don't ever learn
Ruby. You'll just feel all dirty inside. ;)
b) Although using eval can be useful, it's not necessary in this
instance. Instead, try something like this:
function getValue(counter){
var packItem = 'PackItem_' + counter;
var packItemValue = document.item_form[packItem].value;
}
JavaScript object properties may be accessed using either the dot
notation (as you were trying to use with eval) or with the square
bracket notation when the property name is stored in a variable. The
second method is most useful in your case where the property name is
dynamically generated with the counter value.
Hope that helps,
Michael
On Thu, Nov 19, 2009 at 9:39 AM, Merrill Oveson <moveson at gmail.com> wrote:
> Fellow phpers:
>
> >From what I've read using eval is a sin:
>
> function getValue(counter) {
>
> var packitemValue = "document.item_form.PackItem_" + counter + ".value";
> packitemValue = eval (packitemValue);
>
> }
>
> Am I sinning? And if so, how and can someone help me repent?
>
> i.e. how else would I code this?
>
> Thanks
>
> Merrill
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>
More information about the UPHPU
mailing list