Click here to Skip to main content
15,905,781 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Trying to limit a input type=text only decimal values with 2 digits after decimal Pin
simpledeveloper2-Feb-21 6:43
simpledeveloper2-Feb-21 6:43 
QuestionIs there a delicate way to pass calendar events variables in Javascript Pin
Member 1505943129-Jan-21 0:04
Member 1505943129-Jan-21 0:04 
AnswerRe: Is there a delicate way to pass calendar events variables in Javascript Pin
Richard Deeming29-Jan-21 0:16
mveRichard Deeming29-Jan-21 0:16 
GeneralRe: Is there a delicate way to pass calendar events variables in Javascript Pin
Member 1505943129-Jan-21 1:58
Member 1505943129-Jan-21 1:58 
GeneralBuild an entire React application in one command Pin
DonJon28-Jan-21 19:22
DonJon28-Jan-21 19:22 
GeneralRe: Build an entire React application in one command Pin
Richard Deeming28-Jan-21 22:14
mveRichard Deeming28-Jan-21 22:14 
QuestionBest way to trace JavaScript Conflict Pin
ReverseAds10-Jan-21 20:35
ReverseAds10-Jan-21 20:35 
QuestionRe: Best way to trace JavaScript Conflict Pin
Sandeep Mewara10-Jan-21 21:13
mveSandeep Mewara10-Jan-21 21:13 
AnswerRe: Best way to trace JavaScript Conflict Pin
20212a15-Jan-21 8:16
20212a15-Jan-21 8:16 
AnswerRe: Best way to trace JavaScript Conflict Pin
F-ES Sitecore28-Jan-21 21:24
professionalF-ES Sitecore28-Jan-21 21:24 
Questionhow to convert a function in to arrow function Pin
Member 139980429-Jan-21 0:56
Member 139980429-Jan-21 0:56 
AnswerRe: how to convert a function in to arrow function Pin
Afzaal Ahmad Zeeshan9-Jan-21 4:35
professionalAfzaal Ahmad Zeeshan9-Jan-21 4:35 
SuggestionRe: how to convert a function in to arrow function Pin
Richard Deeming11-Jan-21 22:41
mveRichard Deeming11-Jan-21 22:41 
QuestionQuiz Issue Pin
Shobhit Rathour30-Dec-20 3:35
Shobhit Rathour30-Dec-20 3:35 
AnswerRe: Quiz Issue Pin
Afzaal Ahmad Zeeshan9-Jan-21 5:02
professionalAfzaal Ahmad Zeeshan9-Jan-21 5:02 
QuestionReplacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 7:52
professionaljkirkerx21-Dec-20 7:52 
This is part of the old PHP 4.7 App that I'm working on. The last time somebody worked on it was back in 2008, so there is a lot of old outdated stuff in it. One of them is this eval() function.

I read up on it, but I'm still kind of fuzzy on the point of it. If I understand correct, it evaluates the notion of an equation, or string, and returns the outcome if it can be done, or undefined if it can't be done. And then the Mozilla documentation said "Don't use it", and offered work around solutions such as using a function instead.

Looking at this block of JavaScript, I'm having trouble with understanding why it was written this way, and coming up with a rewrite.

So like on Ref 1, it must be a select option element, and it getting the value.
I would think document.getElementByID('document.step2.' + txt + '.value') would be a good replacement, and then check if the element is undefined.

And Ref 2 is thew same thing.

Mozilla says this, in which I get, but confuses me because my eval() is being used different.
I just need help in understanding, and if I am interpreting this correct.
Wrong
function looseJsonParse(obj){
    return eval("(" + obj + ")");
}

Right
function looseJsonParse(obj){
    return Function('"use strict";return (' + obj + ')')();
}
JavaScript
function save(bkType, txt, id , dataType) {        

    let error = false;
    let typeVar = eval('document.step2.' + txt + '.value'); // Ref 1
    let referenceId = '';
    let refDetail = '';
    let quantity = '';

    // Whether to post msrp.phtml or not
    const fPost = true;

    if ('Q' == bkType) {

        typeVar = 'document.step2.' + id + '\$quan' + '.value';
        quantity = eval(typeVar); // Ref 2

    }
    else if ('TQ' == bkType)  {

        typeVar = 'document.step2.' + id + '\$quan' + '.value';
        quantity = eval(typeVar);
        typeVar = 'document.step2.' + id + '\$type' + '.value';
        referenceId = eval(typeVar);

        if ('quan' != data_type)  {

            var typeOptions = eval('document.step2.' + txt + '.options');
            FilterInactivePart(typeOptions);

        }

    } 
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Replacing the eval() function with something faster, more safe Pin
Graham Breach21-Dec-20 8:27
Graham Breach21-Dec-20 8:27 
GeneralRe: Replacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 9:21
professionaljkirkerx21-Dec-20 9:21 
Questionhigher order functions Pin
atomattacker-png21-Dec-20 1:49
atomattacker-png21-Dec-20 1:49 
AnswerRe: higher order functions Pin
Richard MacCutchan21-Dec-20 2:06
mveRichard MacCutchan21-Dec-20 2:06 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 2:21
atomattacker-png21-Dec-20 2:21 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 3:13
mveRichard MacCutchan21-Dec-20 3:13 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:02
mveRichard MacCutchan21-Dec-20 4:02 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 4:36
atomattacker-png21-Dec-20 4:36 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:44
mveRichard MacCutchan21-Dec-20 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.