473,889 Members | 1,818 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 1928
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
3810
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
4116
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
2125
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
3166
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
1658
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
5
1515
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
5943
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
6642
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
3505
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
11199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10791
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
10894
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
10442
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...
1
7997
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
7150
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
5830
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
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.