473,231 Members | 1,575 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,231 software developers and data experts.

Execute javascript command from variable

63
There is a sequence of ProdCode fields; in this case 1 - 3. I would like to populate the strCBFilter variable with the values contained in those fields using a loop:
Expand|Select|Wrap|Line Numbers
  1. document.frmXRefAttachMaint_01.ProdCode1 
  2. document.frmXRefAttachMaint_01.ProdCode2 
  3. document.frmXRefAttachMaint_01.ProdCode3 
  4.  
The code creates each name by concatenating the number in the loop to the
prefix: document.frmXRefAttachMaint_01.ProdCode". Is there a way to have the program do this:
Expand|Select|Wrap|Line Numbers
  1.   strCBFilter = strCBFilter  +  document.frmXRefAttachMaint_01.ProdCode1 
  2.  
using the value of variable strCBFilterCode which contains:
document.frmXRefAttachMaint_01.ProdCode1 with the number changing each time through the loop.

Full Code:
Expand|Select|Wrap|Line Numbers
  1. for(i = 1; i < 4; i++) 
  2. {
  3.   var strCBFilterCode = "document.frmXRefAttachMaint_01.ProdCode" + i + ".value";
  4.  
  5.    strCBFilter = strCBFilter  +  strCBFilterCode 
  6. }
  7.  
//The highlighted code populates the strCBFilter variable with the contents of the strCBFilterCode variable instead of the field the strCBFilterCode variable refers to. In other languages, I was able to execute commands after placing them in variables. Can this be done in Javascript?//
Feb 19 '09 #1
7 5352
Dormilich
8,658 Expert Mod 8TB
I guess you need to pass your strings through the eval() function to get it executed (otherwise it's just a bunch of strings).
Feb 19 '09 #2
rmurgia
63
It worked! Thank you.
Feb 19 '09 #3
Dormilich
8,658 Expert Mod 8TB
I'm glad I could help.
Feb 20 '09 #4
acoder
16,027 Expert Mod 8TB
Instead of eval(), you could use something like:
Expand|Select|Wrap|Line Numbers
  1. document.frmXRefAttachMaint_01.elements["ProdCode" + i].value
Feb 23 '09 #5
rmurgia
63
Thank you. Are there advantages of using this code:

document.frmXRefAttachMaint_01.elements["ProdCode" + i].value

over the eval() function?
Feb 23 '09 #6
acoder
16,027 Expert Mod 8TB
The main benefit here is speed. Using bracket notation (member operators) is much faster - see Note on eval(). You shouldn't get into the habit of bunging everything into eval when there are better alternatives around. You'll notice the benefits when there's more code.
Feb 24 '09 #7
rmurgia
63
Okay, will give it a try and thanks again!
Feb 24 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob Garbados | last post by:
I'm pretty new to php\linux and I'm trying to encrypt a file using gpg from a php page on a linux box and it's not working. The following code works for executing 'ls', but not gpg... ...
1
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If...
1
by: Brendan Jurd | last post by:
Hello all, I've discovered that in 7.4.2 PL/pgSQL, the FOUND variable is not at all affected by use of the EXECUTE command, even if the statement you pass to EXECUTE would set FOUND to true when...
4
by: alberto | last post by:
How can I execute a command of the operating system like "cls" from a C# code? Thank you
1
by: Crash | last post by:
Hi, ..NET v1.x SP1 VS 2003 SQL Server 2000 SP3 Server 2000, XP, Server 2003 I would like to programmatically execute {possibly many} SQL Server batch scripts. Aka I have many scripts that...
14
oll3i
by: oll3i | last post by:
i want to write a bank account programme and use a command pattern where execute method has variable number of parameters. public interface Command { public abstract void execute (String...
3
by: Rahul Babbar | last post by:
Hi, I have the following doubt. Suppose I use the execute immediate statement and the statement to be executed is a Select statement from the sysibm.sysdummy1 table which will always return...
1
by: mikegolden | last post by:
An application I'm working on makes extensive use of output parameters and return values, thus forcing me to use the ADODB Command object to execute the stored procs. For recordset returning stored...
6
by: moongeegee | last post by:
I have compile my java program as myjava.class. And I can run as "java myjava" without any program. As now, I need to execute myjava.class in javascript. Please shed a light how to execut "java...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.