Javascript eval() won't work.

Discussion in 'Javascript' started by tenshi04@gmail.com, Feb 21, 2007.

  1. Guest

    Hi,

    I am trying to get a code snippet from a database and use the snippet
    within the Javascript eval() function. The snippet is a an if-else,
    statement that sets a certain value. Here is the code below:

    -----------------------------------------------------

    var sLogicKey = "ATR_PROD_DIV";
    var sGetLogicSQL = "SELECT LOGIC_TEXT FROM ATR_LOGIC WHERE LOGIC_KEY =
    '" + sLogicKey + "'";
    var oDB = new DataManager(sGetLogicSQL); //gets a connection
    var oRsLogic = oDB.executeQuery();
    var sLogicText = "";
    if (oRsLogic.size() > 0)
    {
    sLogicText = oRsLogic.getRow(0).getString(1);
    }

    sProdDiv = eval(sLogicText);
    -----------------------------------------------------------
    this basically just pulls a string out from the database where the
    LOGIC_KEY field is equal to "ATR_PROD_DIV".
    the result of the query is (and essentially the value of sLogicText):


    --------------------------------------------------------------
    if (sSalesDiv.equals('D') && (sTemp.equals('S5F') ||
    sTemp.equals('S9V') || sTemp.equals('SJC') || sTemp.equals('SVA') ||
    sTemp.equals('SVB') || sTemp.equals('SNH') || sTemp.equals('SVJ') ||
    sTemp.equals('SVH')))
    {
    sProdDiv = 'A';
    }
    else if (sSalesDiv.equals('D') && (sTemp.equals('S3V') ||
    sTemp.equals('STX')))
    {
    sProdDiv = 'B';

    }
    sProdDiv = sProdDiv + '';

    ---------------------------------------------------------
    When sLogicText is passed into eval(), the logic is not evaluated and
    instead, sLogicText value is simply returned back.


    Anyone have ideas as to what might be wrong?

    thanks.
     
    , Feb 21, 2007
    #1
    1. Advertising

  2. <> wrote:
    <snip>
    > When sLogicText is passed into eval(), the logic is not
    > evaluated and instead, sLogicText value is simply returned
    > back.
    >
    > Anyone have ideas as to what might be wrong?


    That would happen whenever sLogicTest's value was anything but a string
    primitive (for example, a String object).

    Richard.
     
    Richard Cornford, Feb 21, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Newton
    Replies:
    3
    Views:
    9,495
    Brock Allen
    Apr 4, 2005
  2. Chad
    Replies:
    4
    Views:
    8,376
  3. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    563
    Karl Seguin [MVP]
    Jun 16, 2006
  4. Alex van der Spek

    eval('07') works, eval('08') fails, why?

    Alex van der Spek, Jan 8, 2009, in forum: Python
    Replies:
    6
    Views:
    1,494
    Bruno Desthuilliers
    Jan 8, 2009
  5. Liang Wang
    Replies:
    8
    Views:
    141
    Ben Morrow
    Feb 2, 2008
Loading...

Share This Page