473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

"cannot assign" workaround?


I want to programically generate some JS variable names in a loop.

The variables are NOT to be array values.

The variable names might be eq0, eq1, eq2....

Inside an ii indexed loop,

eval ("eq" + ii ) = some calculated stuff ;

generates a "cannot assign" error.

So does

"eq" + 11 = some calculated stuff ;
What is the correct way to programatically generate variable names?
--
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
May 29 '07 #1
4 1696
On May 29, 12:42 pm, Don Lancaster <d...@tinaja.comwrote:
I want to programically generate some JS variable names in a loop.

The variables are NOT to be array values.

The variable names might be eq0, eq1, eq2....

Inside an ii indexed loop,

eval ("eq" + ii ) = some calculated stuff ;

<URL: http://www.jibbering.com/faq/#FAQ4_39 >
--
Rob

May 29 '07 #2
Don Lancaster said the following on 5/28/2007 10:42 PM:
>
I want to programically generate some JS variable names in a loop.

The variables are NOT to be array values.

The variable names might be eq0, eq1, eq2....

Inside an ii indexed loop,

eval ("eq" + ii ) = some calculated stuff ;

generates a "cannot assign" error.
Stop mis-using eval.

window["eq" + ii] = //some calculated stuff
So does

"eq" + 11 = some calculated stuff ;

What is the correct way to programatically generate variable names?
Assign them as properties of the window, which they are anyway, using
bracket notation.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 29 '07 #3
On May 29, 5:17 am, Randy Webb <HikksNotAtH...@aol.comwrote:
Don Lancaster said the following on 5/28/2007 10:42 PM:
I want to programically generate some JS variable names in a loop.
The variables are NOT to be array values.
The variable names might be eq0, eq1, eq2....
Inside an ii indexed loop,
eval ("eq" + ii ) = some calculated stuff ;
generates a "cannot assign" error.

Stop mis-using eval.

window["eq" + ii] = //some calculated stuff
So does
"eq" + 11 = some calculated stuff ;
What is the correct way to programatically generate variable names?

Assign them as properties of the window, which they are anyway, using
bracket notation.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
OK, I know how it feels when someone you asked how to do something
tells you that you should do something else instead, though they might
be right at times, no point in not-answering your question too. Try
this:
eval( "eq" + ii + " = " + (some calculates stuff) + ";" );
that should work, though I didn't test it. The point is, you should
make the whole expression appear under eval();

May 29 '07 #4
Darko wrote:
On May 29, 5:17 am, Randy Webb <HikksNotAtH...@aol.comwrote:
>Don Lancaster said the following on 5/28/2007 10:42 PM:
>>I want to programically generate some JS variable names in a loop.
The variables are NOT to be array values.
The variable names might be eq0, eq1, eq2....
Inside an ii indexed loop,
eval ("eq" + ii ) = some calculated stuff ;
generates a "cannot assign" error.
Stop mis-using eval.

window["eq" + ii] = //some calculated stuff
>>So does
"eq" + 11 = some calculated stuff ;
What is the correct way to programatically generate variable names?
Assign them as properties of the window, which they are anyway, using
bracket notation.

OK, I know how it feels when someone you asked how to do something
tells you that you should do something else instead, though they might
be right at times, no point in not-answering your question too. Try
this:
eval( "eq" + ii + " = " + (some calculates stuff) + ";" );
that should work, though I didn't test it. The point is, you should
make the whole expression appear under eval();
You really should think outside of eval(). I realize you seem to be
intimately familiar with its use, but that might be telling a story
about the quality level of your code you may not wish everyone to realize.

If you are going to encourage its (mis)use, you should at least warn the
person you are replying to as to its improper use.

http://jibbering.com/faq/index.html#FAQ4_40

....specifically states its appropriate usage.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
2
by: Andrew | last post by:
VS.net Win 2k3 I'm getting the following error when attempting to debug. I'm not debugging remotely, just a local project. "Unable to start debugging. Cannot find port. Check the remote...
5
by: Francis Shanahan | last post by:
Folks, I have a base page which is the grand-daddy of all my pages. It inherits from System.UI.Web.Page From this I inherit a layout page. From this I inherit the individual pages themselves....
0
by: Mike Schnorr | last post by:
I have a ASP.Net application that uses assemblies from several other solutions. When testing the applications on my machine I build all the referenced assemblies using nmake. The latest assemblies...
1
by: Dgates | last post by:
This request might belong in a "SQL"-related newsgroup, but it's such a pain using Agent to subscribe to a new group (and download its 50,000 messages!) just to ask one question. So, since it...
2
by: athos | last post by:
Dear All, Our project was done in SQL 2000, now we are migrating to 2005. however, there are lots of command such as: a) SELECT * FROM myTableName which, shall be b) SELECT * FROM...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
6
by: Don Lancaster | last post by:
I need to progrmatically do this inside a loop this.fh03.value = fixFloat (Harms, numPoints) ; with the numbers changing per an index. If I try curHvals = "03" ; // (derived from...
4
by: Waldy | last post by:
Hi there, does anyone know the cause of this problem. When I press F5 to debug a C# web application, I get an error message that begins "Cannot create/shadow copy " then various different file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.