473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eval problem

Hi All,
I'm running some javascript over a server side generated web page
and have multiple generated empty select statements, that I want to
populate when the page is loaded. As HTML doesn't do arrays each
select is individually named withe MySelecti where i is an incremental
from 1.
I know all my variables are correct (i, OptionsCount) and my arrays
of MyValues and MyDescription's exist for multiple enteries and if I
bring out an example of what I thought each line would eval too( say
document.MyForm .MySelect1.opti ons[1]=new
Option('Value1' ,'Description1' ) the line works fine, for the life of me
(i'm sure I'm missing something obvious) the eval line won't eval..

for(i = 1; i<=row; i++) {
for (j = 1; j <=OptionsCoun t; j++) {
eval="document. MyForm.MySelect "+i+".optio ns["+j+"]=new
Option('"+MyVal ues[j]+"', '"+MyDescriptio n[j]+"')";
eval(eval);
}
}

Any help much appreciated

Aug 30 '06 #1
3 1922
Pa****@hushmail .com wrote:
I know all my variables are correct (i, OptionsCount) and my arrays
of MyValues and MyDescription's exist for multiple enteries and if I
bring out an example of what I thought each line would eval too( say
document.MyForm .MySelect1.opti ons[1]=new
Option('Value1' ,'Description1' ) the line works fine, for the life of me
(i'm sure I'm missing something obvious) the eval line won't eval..
Don't use eval for this (as a rule of thumb, don't use eval).

document.forms['MyForm'].elements['MySelect' + i].options[1]

Aug 30 '06 #2
Pa****@hushmail .com wrote:
<snip>
(i'm sure I'm missing something obvious) the eval line won't eval..

for(i = 1; i<=row; i++) {
for (j = 1; j <=OptionsCoun t; j++) {
eval="document. MyForm.MySelect "+i+".optio ns["+j+"]=new
This is assigning a string value to a variable (global or local) called
'eval'. If that is a global variable then it may replace the gloabl -
eval - function, or not.
Option('"+MyVal ues[j]+"', '"+MyDescriptio n[j]+"')";
eval(eval);
If the - eval - to which you assigned the stirng is a local variable
then that local - eval - will be making the global eval as it will come
first on the scope chain, thus you would be attempting to call a stirng
here. If the - eval - which the string value was assigned to was the
global one then again you may be attempting to call a string, or if the
global - eval - function did not allow itself to be replaced then it is
the global - eval - function that becomes the argument to your - eval -
call. You just cannot use the same Identifier as the name of a function
you call ant to pass it an argument at the same time, it will not work.

However, don't use - eval - for this at all, use bracket notation
property accessors instead:-

<URL: http://www.jibbering.com/faq/faq_not..._brackets.html >

document.forms['MyForm'].elements['MySelect'+i].options[j] =
new Option(MyValues[j], MyDescription[j]);

Richard.

Aug 30 '06 #3
Richard Cornford wrote:
><snip>
If the - eval - to which you assigned the stirng is a local variable
then that local - eval - will be making the global eval as it will come
first on the scope chain, thus you would be attempting to call a stirng
here. If the - eval - which the string value was assigned to was the
global one then again you may be attempting to call a string, or if the
global - eval - function did not allow itself to be replaced then it is
the global - eval - function that becomes the argument to your - eval -
call. You just cannot use the same Identifier as the name of a function
you call ant to pass it an argument at the same time, it will not work.
I think I know what your saying but I wouldn't want to repeat it.
However, don't use - eval - for this at all, use bracket notation
property accessors instead:-

<URL: http://www.jibbering.com/faq/faq_not..._brackets.html >

document.forms['MyForm'].elements['MySelect'+i].options[j] =
new Option(MyValues[j], MyDescription[j]);

Richard.
My days of become a good javascript programmer seam a long way off,
thanks for the help Richard, worked a treat.

Aug 30 '06 #4

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

Similar topics

33
3796
by: Stuart | last post by:
why won't the following work for(var i=0;i<pics;i++){ eval('img'+i) = new Image(wth,hgt) eval('img'+i+'.src') = 'http://www.mypics/'+i+'1.gif' } basically I am trying to create a numer of placeholders with thier associated imgages!
7
4112
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed the script and special attention was thrown at the fact the script used eval alot. I don't use eval alot in my scripts - but I do use it - and since I always out to learn more / improve my javascript skills, I'm curious why something I thought...
6
2121
by: Roebie | last post by:
Hi everyone, I'm having some weird problem with evaluating the continue statement. Within a for loop I'm trying to evaluate a string (generated somewhere earlier) which basically has the continue statement in it. IE6 seems to have major problems with that as it generates an error "Can't have 'continue' outside of loop". Does anyone know why and/or have a workaround? I haven't tried any other browser since this one is the only one...
18
3164
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
8
1656
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
5
1512
by: iulian.ilea | last post by:
Hi, I have to eval a string stored in a variable, but it's not working. code: ___ function ee($s) { return $s; }
6
5932
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
5
6638
by: wendallsan | last post by:
Hi all, I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns it as the responseText. I want to attach that object to the document (or anywhere else that would allow me to access it later), and to do that, I THINK I need to eval it because it's just a string otherwise. My problem is as soon as I execute a...
12
3491
by: Bill Mill | last post by:
Hello all, I want to have a user able to eval code in a text box. However, if he accidentally types "while(1) { i=0; }" and hits "run", I also want him to be able to hit a stop button such that his browser does not go into an infinite, soul-crushing, interface-locking loop. The stop button would not need to be instantly responsive, but of course the more responsive the better. Short of writing a javascript-in-javascript interpreter,...
0
9685
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
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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...
1
10187
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10018
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
9055
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...
0
5446
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2928
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.