What is the use of document.frmReport - javascript

Can anyone tell me the use of document.frmReport in JavaScript code?
My application uses this but I don't have any information about this. Besides, it is an HTML DOM object from what I've searched on the internet. A speedy answer would be very helpful. The code is like this:
function fnAddItems(strSource,strTarget)
{
var f = document.frmReport;
var doAdd;
var objSourceCombo = eval("document.frmReport."+strSource);
var objTargetCombo = eval("document.frmReport."+strTarget);
var selSourceLen = objSourceCombo.length;
var selTargetLen = objTargetCombo.length;
var strSourceText;
var strSourceValue;
var arrIDs;
var arrIDs1;
var IsMultipleSelected;
var strFormat;
}

document.frmReport returns undefined for me. Also, there's no official documentation about it, and it's not in the specs.
So my guess is it's something that's added to the document object earlier in your application by someone else, and is being used now.
Look for document.frmReport = something (probably an object)
Do you understand why relying on eval and global variables is a bad practice now?

Related

Solve Linear equation with variables in JavaScript

I am trying to use JavaScript to solve the linear equation with variables.
So my try is this:
var CE = parseFloat(document.getElementById("CE").value)
var CF = parseFloat(document.getElementById("CF").value)
var EF = parseFloat(document.getElementById("EF").value)
var x1=algebra.parse("CE^2+2*EF*x-EF^2");
var x2=algebra.parse("CF^2");
var eq= new Equation(x1,x2);
var h=eq.solveFor("x");
I know I should not put the valuable in "" mark, but I do not know where I should put them.
Please help me. Thank you!
You can use template String in ES-6 to simplify writing these complicated string.
var x1=algebra.parse(`${CE}^2+2*${EF}*x-${EF}^2`);
var x2=algebra.parse(`${CF}^2`);
var eq= new Equation(x1,x2);
var h=eq.solveFor("x");

Can't assign querySelectorAll() to a variable - weird behaviour

I was trying to crawl a very old website for a specific tag, I need to get it by it's for= attribute. So I used this piece of code.
var character = document.querySelectorAll("label[for=char_1]");
For some reason it returns an undefined, but I was using this script for a few days now and it worked like a charm. Here's the fun part. Typing that command in browsers console will result in undefined. But typing this alone:
document.querySelectorAll("label[for=char_1]");
Will return a proper NodeList. Why it won't assign to a variable...?
edit: It seems that deleting var and typing character without it will make it work. It's resolved but I would still love to get an answer to "why is this happening"?
edit2:
for (var i = 0; i < 15; i++) {
var character = document.querySelectorAll("label[for=char_" + i +"]");
console.log(character); // this will return [] from the script.
var color = character[0].children[0].style.color;
}
A simple for loop. All I get is Cannot read property 'children' of undefined. But I can type in the very same command document.querySelectorAll... and it will work in the browser and will return NodeList.
I had it working like this in a very hacky script. It worked.
var character1 = document.querySelectorAll("label[for=char_1]");
var characterColor1 = character1[0].children[0].style.color;
edit3:
var character1 = document.querySelectorAll("label[for=char_1]");
var characterColor1 = character1[0].children[0].style.color;
var character2 = document.querySelectorAll("label[for=char_2]");
var characterColor2 = character2[0].children[0].style.color;
// ...
The above code works without a single problem though. I don't think it's DOM not being ready as this code is also run from Greasemonkey script and it works. The only difference is the for loop.
var x = ""; // returns undefined, because it's a var assignment.
var elements = document.querySelectorAll('div');
That's expected behavior when pasted into the console.
edit: It seems that deleting var and typing character without it will make it work. It's resolved
I'm afraid you're creating a global scope variable now. or perhaps characters is an already defined variable in that scope.
Buhah, as I said in edit 3 "the only difference is the for loop". I was so busy trying to find an answer in the DOM-related things that I made the simplest mistake ever done in programming.
See?
char_1
With...
for(var i = 0...)
0! And I was testing char_1 in the browser instead of char_0. Which - truly - returns [] instead of something useful. Time to go on a holiday break I guess, my brain seems to be there already. :)

ExtJs - best way to check if Ext.Array is empty?

In ExtJS, using an Ext.Array (after using Ext.Array.difference), I get a resulting array and would like to know the best way to check if the array is empty?
I did use theArray.length as one could do in javascript, but I'm wondering if there is a better way/faster to acheive that? (At first I thought that isEmpty would help but it seems to be working on object, not array)
You can easily add this to the Array prototype like this:
Array.prototype.isEmpty = function(){
return !this.length;
};
var a = ['a','b','c','d'];
var b = ['b','d','f','h'];
var c = Ext.Array.difference(a,b);
var d = [];
console.log(c.isEmpty(), d.isEmpty());
Hope it helps :)

How to call studentt method of jstat to get result?

I have a question about how to use the distribution functions within the jstat library. Specifically, I am focused on studentt.
I've tried this:
var alphaLevel = 0.05;
var degreesOfFreedom = 18;
// the answer I want to get is 2.100922
tStat = jStat.studentt(alphaLevel,degreesOfFreedom);
// but all that is returned is an object with
// members _a,_b,_c (_a=alphaLevel, _b=degreesOfFreedom,_c=undefined).
As explained on the jstat github site, there is a difference between static and instance functions. However, it is above my experience with javascript as to how to do this.
Can anyone explain how to properly call the studentt function and get the proper result?
Thank you!
The usage follows this documentation: http://jstat.github.io/distributions.html#jStat.studentt
So in your example you have two options. Either you can get the result immediately:
var tStat = jStat.studentt.pdf(alphaLevel, degreesOfFreedom);
Or you can return an instance that allows you to pass in multiple values of alpha:
var tStat = jStat.studentt(degreesOfFreedom);
var a1 = tStat.pdf(alpha1);
var a2 = tStat.pdf(alpha2);

Store jQuery objects in an array/object

I want to create a JS array that contains jQuery objects like this:
var oFormFields = new Object;
oFormFields.label = $(document.createElement('label'));
oFormFields.input = $(document.createElement('input'));
Since this crashes my code, i expect this is not possible. Any alternatives? This is my simplified version, I want to include some other properties so I'm able to re-use this in my code when building dynamic forms.
EDIT: Seemed this did work after all... what I wanted to do, was something like this:
var oFormFields = new Object;
oFormFields.name_field.label = $(document.createElement('label')).addClass('nam_field');
oFormFields.name_field.input = $(document.createElement('input')).addClass('nam_field');
This does break my code. I'm pretty new to jQuery, coming from a PHP background I'm having some troubles adjusting to the correct way to work with arrays / objects.
Just use it like this:
var oFormFields = {
label: $('<label />'),
input: $('<input />')
};
You can create the element directly using jQuery. Furthermore, as mentioned in the comments, you should prefer the object literal notation over the new syntax.
var arr = [];
var oFormFields = {};
oFormFields.label = $('<label/>');
oFormFields.input = $('<input/>');
arr.push(oFormFields);
.........

Categories