Problem With Eval

Apr 17, 2006

Here is my code.

function CallDisplay()
{
nodeobj=new mynode();
x="displayId("+nodeobj+")";
eval(x);

}
function displayId(node)
{
alert(node.myid);
}
function mynode()
{
this.myid="aa";
}

In CallDisplay() I am getting the error as "Microsoft JScript
Compilation error ']' expected". Any one can suggest me how to
overcome this.

View 8 Replies


ADVERTISEMENT

Eval() How Else

Jul 23, 2005

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);
}}

View 4 Replies View Related

How To Use Eval?

Jul 23, 2005

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:

this.orde = vals[0];
this.no = vals[1];
this.kml = vals[2];

and so on?

View 7 Replies View Related

Need The [] In Eval

Nov 16, 2006

how comes the following doesnt work

fieldNotes2=eval("Message.notes["+id2+"]");

i believe it's because of the [] but i need to keep them!

View 9 Replies View Related

Using Eval()

Jan 28, 2004

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...

code:

<html>
<head>
<title>test</title>
<script language="JavaScript">

function submitCode(){
var the_code = window.document.form_1.textarea_1.value;
var run_the_code=eval(the_code);
}

</script>
</head>
<body>
<center>
<h1>write some code!</h1>
<form name="form_1">
<textarea name="textarea_1" rows=10 cols=40>
</textarea>
</form>
<form onSubmit="return false;">
<input type="submit" value="submit your code" onClick="submitCode();">
</form>
</center>
</body>
</html>

very simple stuff, but for those of you who are unfamilir with eval, its pretty cool, huh?

View 3 Replies View Related

Eval And Continue

Aug 23, 2005

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:

View 6 Replies View Related

Javascript Eval

Feb 2, 2006

I am trying to do the following but i get an error, is there no way i
can use eval to print have it assigned to a predeterminded variable.

eval (object_name + "_CalCalendar") = new CalendarPopup(object_name);

Cannot assign to function result.

View 2 Replies View Related

Eval Problem

Aug 30, 2006

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..

for(i = 1; i<=row; i++) {
for (j = 1; j <=OptionsCount; j++) {
eval="document.MyForm.MySelect"+i+".options["+j+"]=new
Option('"+MyValues[j]+"', '"+MyDescription[j]+"')";
eval(eval);
}
}

View 3 Replies View Related

Can I Avoid Eval() Here?

Nov 23, 2006

I am trying to assign an "onclick" event to a dynamically-created DOM
element (an image).

I have read countless times that "eval()" is to be avoided at all costs.
However, I cannot seem to get my new onclick to work without it.

Here's what I have so far:

myeval = 'detachFile(this);'
detachImage = getElementById('detach-jfhahhf');
detachImage.onclick = function() { eval(myeval) }

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.

Can that be done without the eval()?

View 6 Replies View Related

Nifty Use For Eval()

Sep 8, 2002

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.

<HTML>
<HEAD>
<TITLE>Evaluator</TITLE>

<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">

</HEAD>
<BODY>

<FORM>
<TABLE WIDTH="100%" HEIGHT="100%">
<TR>
<TD COLSPAN="2" HEIGHT="100%"><TEXTAREA NAME="script" STYLE="width: 100%; height: 100%"></TEXTAREA></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><INPUT TYPE="BUTTON" VALUE="eval" OnClick="eval(this.form.script.value);"></TD>
<TD ALIGN="CENTER"><INPUT TYPE="RESET" VALUE="clear"></TD>
</TR>
</TABLE>
</FORM>

</BODY>
</HTML>

View 2 Replies View Related

Eval Function

Apr 12, 2006

In Visual Basic this is easy to do, but I'd like to do it in JavaScript (without writng my own).

I'd like to put a text box on a form so the user can type something like:

3+5*(sin(90))^2

and have the answer to the equation displayed.

I guess it would be possible to translate it into a javascrip command

x=Math.pow(3+5*(Math.sin(90)),2) and then execute the translated line using Eval(x);, but maybe there's an easier way. Any thoughts?

View 2 Replies View Related

Better Way To Evaluate Than Eval()?

Nov 3, 2010

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]..

View 7 Replies View Related

Looking For An Eval Alternative?

Aug 29, 2009

this is the code I'm working on:

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.

View 2 Replies View Related

Using Complete <script> Tag In Eval Is Possible ?

Jan 14, 2006

I am try'g to send window.location.href to the server script who will
generate dynamic javascript according to the referral name comg in as
param:

<script language="javascript" src="NO JAVASCRIPT CAN BE USED HERE" />

So I am see'g If I can use eval todo something what I am doing

I have tried almost everything, following is being last one ....

View 21 Replies View Related

Eval And Mutireplace, Which Is Faster?

Dec 26, 2006

I want to implement the template for a object output. I have two methods as follow:

View 1 Replies View Related

Using Eval() For Function Definition

Feb 19, 2007

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:

this.items[i].onclick = eval( "function() { alert( " +
this.values[i] + "); }" );

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?

View 7 Replies View Related

Allow Math To Be Eval'ed - But Not Malicious ?

Feb 10, 2011

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?

View 3 Replies View Related

Stop The Eval Sorting In IE9?

Jul 6, 2011

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"}

[Code]....

how to stop the array sorting in IE9.

View 3 Replies View Related

Eval() Not Executing Code ?

Nov 9, 2011

I set up a variable that should replace HTML code when run but it doesn't seem to be doing that...

Here it is:

Any idea why? (My console isn't showing any issues)

View 13 Replies View Related

Replacing Eval() URGENT!

Mar 13, 2006

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;
}

Ive tried many thing, and had no sucess.

View 2 Replies View Related

Javascript + Firefox + Eval()

Jul 29, 2004

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:

View 2 Replies View Related

Using Eval() With Ajax Response

Apr 3, 2008

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:

Code:
var myObj = eval ( xmlhttp.responseText );

View 14 Replies View Related

Using Eval To Parse A JSON Text

Jun 9, 2006

Can anyone explain me why you need to add open and close parenthesis to
a JSON text in order to use eval() to parse it?

For example:

var json = "{a: 'abc', b: 'def'}";
var obj1 = eval("(" + json + ")"); //ok!
var obj2 = eval(json); //syntax error!

why are parenthesis necessary?

View 2 Replies View Related

Eval() Delivers Incorrect Results?

Sep 27, 2006

I noticed weird results when using eval() to do some simple calculations. Here are a few eval() statements and the corresponding results from javascript:

eval("1.2+0.97") =2.17
eval("1.2+0.98") =2.1799999999999997
eval("1.2+0.99") =2.19
eval("1.2+0.981") =2.181

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.

View 4 Replies View Related

Eval And Non-English Characters Conflict?

Nov 7, 2006

I am pulling data off a server via AJAX, and some of that data has
non-English characters in it. The data is in the form of a json: Code:

View 12 Replies View Related

Eval Not Working With Firefox / Sort Out This?

Nov 4, 2009

I've following code that gets values from labels and assigns to variables. code...

it works fine in IE but not in firefox.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved