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 had a look at sIFR.js code after parsing it and I have a question about function syntax. For example
var f=function(){ // statements here }();
What is the purpose if the second set of parentheses following the closing brace? Is the intention to execute the function immediately after it has been defined?
Most functions in sIFR.js do not have this syntax, but a few do.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
[code]....
The practical scenario is I have several functions attached to the jQuery ajaxSucess event. Each function needs to execute once during initial load and after when the JQuery ajaxSuccess event is fired. So I am just looking to see if I can eliminate a a few lines of code and learn something new in the process, that is really all.
Throughout the world in general, ISO 8601 Week Numbers are used, in which weeks are numbered 01 upwards and Week 01 contains the first Thursday of the Gregorian Calendar Year.
There are, however, odd parts of the world where that standard is not followed.
Ignoring for the moment cases in which week 1 is not more-or-less at the beginning of the calendar year, what other definitions, stated exactly, are used?
I'm trying to grab all of the elements of a DL, specifically the <a href>'s grouping them by the DD's. I suppose if I can just get them into groups I can get the href's later. The hard part is getting them grouped as explained below. For example...
Is there a way to say, loop through the DL until it finds a DT. Whe it finds one, grab it and all of the DD's that immediately follow it .. until it comes to another DT. Group it with its DD's and continue until no more DT's are found.
Then maybe take these collections and possibly populate an array with the groups?
There is an effect I would like to do but I don't know how it is done. To see something like it go to:[URL].. then mouseover the right side items under "most recently". It seems like there is a dt link which when mouseover occurs the dd data is presented.
I have pairs of terms and short definitions in a table. I want to display a longer definition in a box below the terms table when the term is clicked on. The box needs to disappear if clicked on. [code]...
I am trying to use multiple instances of this little show/hide script for a definition list on the same page. However, the problem is that the definition list must be given an ID, and this can only be used once on a page. [URL]. How would I go about changing this to a class so that I could use it more than once on a page (i.e. multiple definition lists as opposed to one big one)? I changed all of the getElementById to getElementByClass and it didn't seem to work.
I've got a website with font sizes using 'em's. I've made it so that in my 'body' CSS styling, I can change the font size and it changes it right throughout the whole site.
I have hyperlinks to increase and decrease the font size but have no idea how to get the links to change the 'font-size' property in my 'body' definition. As a secondary requirement (but not essential) I also need to remember this value and store in a cookie so the user doesn't need to keep resizing the page on every reload.
I've always wanted to help second-language English speakers access my site better, by offering a 'double-click on a word' definition in other languages. I had a useful script for some years which was rather dated, and ceased to work if there was an iframe on the page for some reason. Anyway, I found a very good solution at [URL]However, this opens the definition in a new tab/window.
Having experimented with it opening in a popup, I found problems in getting the popup to regain focus if someone had not closed it before looking for another definition. And anyway, popups can get blocked. So I found a nice layer/iframe solution at [URL] though their positioning of the layer is poor, at least in FF because it slides too far down below the bottom of the page. Their script is: [URL]I have modified that to work with dictionarist and stripped out their own floating part of the script, so that it works with position fixed for everything except IE6. But for IE6, I need to still change this from position fixed to position absolute, and then use a script to float the box.I have been trying the script I use successfully elsewhere in a vaguely similar context:
which has a call to startFloat(); near the end, which is based on their own floating script nearer the top of [URL] which I have removed. (Doubtless the references to Netscape (RIP) can be removed.)
I am doing a distionary page with javascript and I am trying to get it so that the definitions come up when the word they are for is clicked on.
Here is my javascript Javascript Document var filename = "dictionary.js"; function loaded(which){ alert(which + " loaded"); }/**/ function showInfo(which){ var placeholder = document.getElementById("definition"); var source = whichInfo.getAttribute("href"); placeholder.setAttribute(source); alert("showInfo called"); return false; }function prepareList(){ if (!document.getElementsByTagName || !document.getElementById) return false; var words = document.getElementById("words"); if (!words) return false; var links = words.getElementsByTagName("a"); for(var i = 0; i < links.length; i++) { links[i].onclick = function(){ showInfo(this); return false; }} alert("prepare list done"); }function init(){ prepareList(); }loaded(filename); window.onload = init;
Here is my html <!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 StrictEN" "[URL]"> <html xmlns="[URL]"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Dictionary DOM Scripting</title> <link href="../styles/main.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="dictionaryScripts/dictionary.js"> </script> </head><body> <div class="page"> <div class="nav"><ul> <li><a href="../home.html">Home</a></li> <li><a href="../form/form.html">Form</a></li> <li><a href="dictionaryCSS.html">Dictionary with CSS</a></li> <li><a href="dictionaryDOM.html">Dictionary with DOM scripting</a></li> <li><a href="discussionPage.html">Discussion</a></li> </ul></div><div class="header"> <h1>Dictionary with DOM Scripting</h1></div> <div class="mainContent"> <div id="words"><h2>L</h2> <p>Click on the word to get a definition</p> <dt><a href="lecturer.html">LECTURER, n.</a></dt> <dt><a href="learning.html">LEARNING, n</a></dt> <dt><a href="liar.html">LIAR, n.</a></dt> <dt><a href="love.html">LOVE, n.</a></dt></div> <div id="definition">Choose a definition</div> </div></div></body></html>
I am looping through an array of objects and creating an <li> element for each one and appending to a <ul> in the DOM. Works fine.During the looping I am also attached a 'details' object as data for the list element:$(thisListItem).data('details',{<obj>});Later, I am using the selector:$('ul#images_list li')to attach an on click function for each <li> element.In the click handler I am reading the data 'details' object for the <li> element:dataDetails = $.data(lotImage,'details');and, using the jAlerts plugin, I am opening a jPrompt which asks for the user to enter a price.
The jPrompt call includes a callback which receives the entered value as a parameter. The callback uses the value to 'post' the updated value, via $.ajax, to a server side unction.After OK is clicked in the jPrompt popup, in Firebug, I get an error that the dataDetails is undefined and it lists the line number in the click handler where I originally read the data object from the <li> element.I don't really understand why it should care after the click event has fired and the jPrompt callback has been invoked
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.