473,804 Members | 3,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 1723
On May 29, 12:42 pm, Don Lancaster <d...@tinaja.co mwrote:
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.javas cript 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.javas cript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptT oolbox.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

....specificall y 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
3130
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 <class T> struct rebind { typedef foo<qqq> other;
2
2310
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 machine name." Any insight is appreciated.
5
1749
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. The problem: My pages can no longer be brought up in the designer. I'm using Visual Studio 2002 and these pages are written in asp.NET with the code
0
2094
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 get placed in a common directory that is referenced by my ASP.NET app. Occasionally I receive the following error: value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName" (there are a lot of these for different...
1
1860
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 deals with an ASP.NET app, I thought I'd ask here. ============================================== I am using Web Data Adminstrator, which I downloaded recently from the Microsoft site. I get an error when I create tables or columns:
2
1880
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 myLoginId.myTableName
3
16520
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 something in PHP that I don't have? Do I need to install more Linux packages? Or adjust PHP in some way?
6
4117
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 index to provide leading zero)
4
2982
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 names. Sometimes I can debug, other times I get the message above. Regards, Steve W.
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.