Javascript eval() won't work.

T

tenshi04

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.
 
R

Richard Cornford

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top