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?
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?
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.
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.
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’.
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.
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?
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).
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.)
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?
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.
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.
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.
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: