given that I have a js file included which is written programatically and I
can't change it. I would like to know how to do the following using
something other than the deprecated eval().
whats in the js file
var numArrays=something;
var data0 = new Array();
data0.name="name";
data0.data="some data";
var data1 = new Array();
data1.name="another name";
data1.data="some more data";
etc ....
function getData(arrayName) {
for ( var i=0;i<numArrays:i++) {
var el=eval('data'+i);
if (arrayName = = el.name) doSomething(el.data);
}}
var fns = ['orde', 'no', 'kml', 'snf', 'td', 'ty', 'tn', ...up to 21 elms...]; var snv = new Array();
var vals = new Array(); for (i = 0; i < N; i++) { for (j = 0; j < fns.length; j++) vals[j] = some value; snv[i] = new makeData(vals); }
function makeData(vals) { for (k = 0; k < vals.length; k++) //the following line doesn't work eval("this."+fns[k]+"="+vals[k]); //neither this one this.eval(fns[k]) = vals[k]); }
how can i make it without writing it the long way:
I've made a funny program using eval()...it will let the person(on the page) to write javascript and have it compile(if thats the right word for it)! its quite cool, i dont know how handy it might be, but here it is none the less...
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 available (company policy).
I have included some code to reproduce this behaviour. The first and second if statements of the testeval function behave as expected. The third one however produces the mentionned error. Code:
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.options[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..
This works perfectly fine for me, but this is a web-app that will be exposed to public users, and I obviously don't want them being able to eval anything if i can help it.
i came up with the following, to help me test the syntax of functions while i'm writing them. i've only been using it for a day or two, but so far, it's been really handy.
I have a script that will loop through all the INPUT elements of a form; if the input is a submit it will disable the submit (or enable the submit, depending upon what is passed to the function.) I hate using eval() - I avoid it whenever I can! Is there a better way to dynamically process the ".disabled = 'true'/'false';" portion?
Code: var tabs = new Control.Tabs('menu'); var pattern = 'tab='; var nStr = location.href; if(nStr.match(new RegExp (pattern,'gi'))){ var id = nStr.split(pattern);
[Code]...
It searches for the query string 'tabs=' and then splits the result to get the id of the tab. Then it uses this to set the active tab. If the url doesn't include the query string it set the tab to the first one.
The code works but it uses Eval to convert the id string (id[1]) to a variable and I was wondering if there was an alternative.
I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code:
function BigObject() { this.items = new Array(); this.values = new Array(); this.addItem = function( item ) { this.items[this.items.length] = item; } this.makeHandlers() { var i, length = this.items.length; for ( i = 0; i < length; i++ ) this.items[i].onclick = function() { alert( this.values[i] ); }; }}
However, this last code (makeHandlers() method) doesn't work since the expression "this.values[i]" automatically belongs to this new anonymous function, and therefore isn't valid (since the new anonymous function(s) don't have the "values" attribute. So I tried the following:
and it worked! ... in Firefox only :( Internet explorer returns "undefined" for eval( "function() { /* whatever */ ); } " ), for the same things Firefox perfectly understands, and if I try to make it a handler, an exception is fired in IE. What do I do? Did I come to the right conclusion with IE or am I making a banal mistake? Do I need to find another way of solving this or is there a fix to this solution?
I have a website that allows users to enter complex mathematical formulas into a text field and evaluates them.
I am currently using eval() because it not only can handle all the standard mathematical functions, but also gives them access to the Math object. That way the users can use functions such as Math.max() and everything else.
I realize, though, that using eval is evil, I assume because a malicious user might throw in some more damaging javascript that would be run without checking it. (That's why eval is evil, right?)
Is there a way that I can allow my users to construct complex mathematical formulas and use the Math object (or an equivalent) without potentially opening my site up to harm?
in IE9 Browser list of country names sorting on keys. we are using Ajax javascript:
var data= remoteRequest(url); the data like data={" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"}
Im not all to sure what I can do right now. I have a script that I wrote for a userlookup on some website, problem is they have filtered out some key elements, to keep hackers away. Now, heres my problem. How can i make this return the same value, without using eval()
function doc() { var f = Array (1); f[0] = 'var d = doc' f[1] = 'ument;' eval(f.join('')); return d; }
I have a script that uses eval() and it works great under IE but it craps out when eval() is called in firefox. Just ignore all the commented out alerts, it is for testing purposes. Code:
I am wondering how possible it is to use eval() to parse javascrpt that is pulled in through ajax(innerHTML)? I have found a few notes about this, such as:
I noticed weird results when using eval() to do some simple calculations. Here are a few eval() statements and the corresponding results from javascript:
This can happen with other numbers as well, but certainly not with any combination. I have confirmed this on Firefox and Safari, two different versions of OS X and both Intel and PowerPC Macs.