468,765 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Help with "cannot assign string" error


I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)
I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]

The right side of the equation works just fine elsewhere.
As does this.fh03.value elsewhere.

eval (...) does not work as it looks up the previous fh03 value rather
than replacing it with a new one.

What is the correct way to programatically loop calculated values with
fancy names?

Is there a command for string to named variable conversion?

--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #1
6 3819
Don Lancaster wrote:
>
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.
Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

--
Ian Collins.
Apr 29 '07 #2
Don Lancaster wrote:
>
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)
I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]
That seems a fairly clear and obvious error report.
The right side of the equation works just fine elsewhere.
No, there are no circumstances where you can assign a value to a string.
As does this.fh03.value elsewhere.
Your - this.fh03.value - is a property accessor and so can be the
destination for an assignment.
eval (...) does not work as it looks up the previous fh03
value rather than replacing it with a new one.
Eval would 'work' if you evaled the entire expression, but assigning to
the return value of a function call is not ever allowed (and not ever
meaningful).
What is the correct way to programatically loop calculated
values with fancy names?
Using bracket nation property accessors instead of dot notation property
accessors:-

<URL: http://jibbering.com/faq/#FAQ4_39 >
Is there a command for string to named variable conversion?
Variable names are strings, but - this.fh03.value - is a property
accessor not a variable name.

Richard.

Apr 29 '07 #3
Ian Collins wrote:
Don Lancaster wrote:
>>I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.


Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);
Looks like an interesting approach.

Except it returns "undefined" for [value].
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #4
Don Lancaster wrote:
Ian Collins wrote:
>Don Lancaster wrote:
>>I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.


Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

Looks like an interesting approach.

Except it returns "undefined" for [value].

But this works. Not sure why...

this [curHvals]["val" + "ue"] = fixFloat (Harms[ii], numPoints)

--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #5
Don Lancaster wrote:
Don Lancaster wrote:
>Ian Collins wrote:
>>Don Lancaster wrote:

I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

Looks like an interesting approach.

Except it returns "undefined" for [value].

But this works. Not sure why...

this [curHvals]["val" + "ue"] = fixFloat (Harms[ii], numPoints)
So does...

this [curHvals]["value"] = fixFloat (Harms[ii], numPoints)
Apparently quotes are required.
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #6
VK
On Apr 29, 7:07 am, Don Lancaster <d...@tinaja.comwrote:
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)

I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]

The right side of the equation works just fine elsewhere.
As does this.fh03.value elsewhere.

eval (...) does not work as it looks up the previous fh03 value rather
than replacing it with a new one.

What is the correct way to programatically loop calculated values with
fancy names?
If I understood your problem properly then I would form the question
in some other way:

- How to access form controls using run-time generated control names
(so they cannot be hard coded as literals in my program).

- Use squared brackets notation with expression in it:
refFormElement.elements["fh"+curHvals].value =
fixFloat(Harms[ii],numPoints);

Apr 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bruce Russell | last post: by
4 posts views Thread by Don Lancaster | last post: by
7 posts views Thread by php_mysql_beginer911 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.