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


ADVERTISEMENT

Document.evaluate

Oct 14, 2006

i would like to evaluate a xpath expresion inside an iframe.

this is what i do :

1. find the iframe :

var f = document.getElementsByTagName('iframe');
2 evaluate the expresion :

var iterator = document.evaluate("//a", f[0], null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

var aElement = iterator.snapshotItem(0);
alert(aElement);

the problem is that this expresion gives me the anchor of the root document, not the anchor inside of the iframe.

View 6 Replies View Related

How To Use Variables In Document.evaluate()

Nov 21, 2006

I met a problem when using document.evaluate() to get text content
using XPath, my code is as follows:

nodes = document.evaluate("/html/body/div/ul[1]/li[5]", document,
null,XPathResult. UNORDERED_NODE_SNAPSHOT_TYPE , null);

in the XPath expression "/html/body/div/ul[1]/li[5]", I need to
traverse from li[1] to li[5],
so I should use a variable here , like this:

for (index =1; index<6; i++)
{
nodes = document.evaluate("/html/body/div/ul[1]/li[index]", ....);
// the variable index here is invalid!
}
my question is: How to use the variable in XPath expression?

View 1 Replies View Related

JQuery :: Parsing XML With IE - Cannot Evaluate Value?

May 7, 2009

The following example works great in Firefox, and Chrome but fails miserably in IE (6,7,8). I'm running JQuery 1.3.2 if it makes a difference:
$('resp',"<root><resp>value</resp></root>").text();
That evaluates to "value" in everything except IE.

View 3 Replies View Related

Evaluate Drop-down Based On Text?

Aug 31, 2009

Curious about the following issue. I currently have a dynamic drop-down based on the value of each option.. If selection in top drop-down is B it will show all options with a B contained in the second/resulting drop-down.

Now - I also want to evaluate the options by having the script check for a few keywords..

Example - have it evaluate the drop-down on page load for options with text containing 'blah123' (ex. <option value="0323G">Qwerty - blah123</option>). And if any of the options have that text the script will generate an additional drop-down menu allowing you to select blah123 or other specified text. Say another thing I'd like to search each text string for is 'abump'. If there is 'blah123' and 'abump' contained within the drop-down, a third drop-down menu will be generated (as said before) with only blah123 and abump as options. Whichever of these is selected will narrow down the options available in the final drop-down menu.

View 4 Replies View Related

Evaluate Last 4 Characters Of File Name Using Javascript

Dec 31, 2007

I have built a page on a recruitment website which allows users to upload their CV via ASPUpload i.e a browse button. However I want to limit the file type to just MS Word documents as I do want them uploading large PowerPoint files etc. My idea is to have some javascript which evaluates the last 4 characters of the file name to ensure it is .doc
So if they try to upload anything other than a .doc file a dialogue box will appear stating that they must only upload MS Word Document (when they click the ‘Upload CV’ button).

Does anyone know how I can evaluate the last 4 characters of the file name? Once the user has browsed to their CV on their PC the path & file name will appear in a text field called ‘CV’.

View 6 Replies View Related

Evaluate Options In Dropdown For Unique Selection?

Jul 23, 2005

I don't know how to evaluate the no-blank selections against each other from a form as follows: .

I have a form with 6 dropdown fields, each containing a selection of 30 options (the 30 options are the same for each dropdown list). The user needs to select 'one of the 30 options' from each dropdown selection, but each option they select must be unique (no duplicate selections) or it must be left blank. E.g. The user can select Option3 within "dropdown1", but must select a different option for the other dropdowns - OR leave them unselected.

View 10 Replies View Related

Switch(n) Does Not Correctly Evaluate Case / Solve This?

Oct 18, 2009

I am returning the present time - then using the .substr to remove all digits except the last two on the right (i.e effectively returning the value 32 from 65344532) I am then looping, subtracting 11 from that number until the value is less than 11. The intent being to then return the value from the appropriate matching array ID code...

The problem arises with evaluating two digit numbers beginning with zero - In cases where the last two numbers are greater than 09, the looping returns a 1 digit number for valuse less than 10, in cases where the last two digits begin with zero the loop will not begin. I have attempted to use the switch(n) to determine if any 01, 02, 03 ... etc exists but this is not evaluating correctly - is this due to using the date/time object and if so is there a good way to convert this to either a numeric or string datatype where the case can be evaluated correctly?

View 11 Replies View Related

AJAX :: JSON Object Fails To Evaluate

Jan 20, 2010

I am trying to populate page elements from an AJAX call, which returns JSON.

For some reason, JSON that looks like this, fails to evaluate, I'd like to understand what's wrong with it.

JSON:

Code:

View 2 Replies View Related

Using Document.Evaluate Function On HTML String?

Oct 8, 2010

I was wondering if it's possible to capture a piece of HTML using XPath where the source is a sting rather than a document. I know how to use xPath and document.evaluate() as I've used it before on actual web pages - I just don't understand how to run it on a string of HTML.

E.g. if I have this string:
var stg = "<div>The best-laid schemes o' <span>mice</span> an' men</div>";
I'd like to convert this string into something that I can run the document.evaluate() on so that I can find the contents of the SPAN element (without loading the string into a real browser page).

View 3 Replies View Related

Foist Javascript Into Another Frame, And Evaluate It In The Target Context

Dec 16, 2006

I have an outer page and an inner iframe. The outer page calculates some
javascript, and wants the inner frame to run it. The inner frame should hit
a page on the same (private) web server, so this is not a cross-site
scripting attack. But I would prefer not to taint the target page with any
extra logic to do this. (I will if I must.)

The calling page has these elements:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<span id='update_me'>yo2</span>
<iframe id='grinder' src='sample.html' >
</iframe>

So here's most of the page which the iframe hits:

<script src="/javascripts/prototype.js" type="text/javascript" />...
<body bgcolor='silver'>
<span id='update_me'>yo</span>
</body></html>

Note that both the outer and inner page have a span with the same ID.

This question will resemble a JavaScript FAQ - how to evaluate Javascript on
the fly, or how to reload a JS file. The answers on the web generally do not
transport the JS across a frame boundary, so they don't address the bug I
encountered, and I can't tell if prototype.js or IE is at fault.

The outer page calls Ajax goodies that generate some JS looking like this:

Element.update("update_me", "here I B");

The page sends that, as a string, into this JS (in application.js):

function update_grinder(sauce)
{
var grinder = $('grinder');

if (grinder)
{
var doc = grinder.contentDocument;
if (!doc) doc = grinder.document;
if (doc)
{
evaluate(doc, sauce);
return;
}
}
document.write("your browser sucks");
}

So that contains enough logic to find the iframe's document, and it works
for Firefox, IE, Konqueror, and Opera. The code calls evaluate() with the
document where we need the evaluation context, and the string with our
source.

Here's evaluate():

function evaluate(doc, sauce)
{
var s = doc.createElement('script');
//s.defer = true; // <-- no effect
s.text = sauce;
var body = doc.getElementsByTagName('body').item(0);

if (body)
{
body.appendChild(s);
return;
}
body = doc.body;
if (body)
{
body.appendChild(s);
return;
}
}

That creates a <scriptblock, sticks our string in as its contents, and
pushes the block to the end of our <bodytag. Now here's the bug:

Firefox updates the inner <span id='update_me'>, and IE updates the outer
one.

If I remove the outer <span id='update_me'>, then IE simply can't find it
and throws an error. Even though it evaluates a script block clearly in the
context of the inner iframe.

I have tried calling the script from setTimeout, and from a button's onclick
handler.

Is there some script.aculo.us way to fix (yet another) bug in IE? Or is this
a bug in prototype.js?

View 15 Replies View Related

Evaluate JS Inline - Pass The Current Window Location Through A Hidden Input To A Php Form Handler

Aug 3, 2010

I need to pass the current window location through a hidden input to a php form handler. I tried this:

Code: <input type='hidden' name='curpage' value='javascript:window.location'>

And this: Code: <input type='hidden' name='curpage' value='javascript:print window.location;'>

View 2 Replies View Related

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

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

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

JQuery :: Evaluate Component Of AJAX Response After Injecting HTML Component In Page?

Nov 1, 2010

You have an AJAX request and the response is mixed HTML + JavaScript. The javascript is referring to elements in the HTML component. Currently the JavaScript gets evaluated first thing when success is triggered and the HTML is returned as a parameter. Obviously this is not going to work ( in this scenario anyway ). As a previous Mootools user I was used to Request.HTML's responseJavaScript parameter and evalScripts option. None of there options are available in the $.ajax implementation.

P.S. I know I could make the javascript a file and load it separately. I know I can make my response JSON and have the js and html in separate properties of the JSON object. I want neither.

View 4 Replies View Related

Document.evaluate Regexes - Get All The "a" Elements With The Href Attribute

Jul 26, 2011

I want to get all the "a" elements with the href attribute in this form: [URL] where any can be a string containing just letters and/or numbers. I'm new to regex and XPath so i can't get it right. I digured it out the regex but i'm not sure if it's 100% correct:

[Code]..

View 2 Replies View Related







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