0

CodeMirror JavaScript Execution Error

asked 2012-01-03 05:48:07 +0800

siva477 gravatar image siva477
57

updated 2012-01-03 05:52:03 +0800

Please Give me Suggestion to solve this Variable Declaration Error. How can i declare new variable without considering JavaScript execution process...

Thanks in Advance.......
Example code:

if( custAge   <  21  ){
  Result ='(var pmt = Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;
           pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;  
           pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;
           pmt = pmt +  Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)';
  return;
}

Result Error:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: unterminated string literal (<Unknown source>#2) in <Unknown source> at line number 2

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-01-03 14:39:10 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2012-01-03 14:40:25 +0800

Hi siva477,

It denotes the javascript engine find a single quote and think about a string is started,
but it can not find the other single quote finish that string.

Please try the sample below, the "Result" is a one line string,
the Result2 use '+' sign to concatenate several parts of value.

var pmt;
var Result = '(var pmt = Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;  pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100;pmt = pmt +  Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)';
var Result2 = '('+ (pmt = Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)
				+ (pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)
				+ (pmt = pmt + Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)
				+ (pmt = pmt +  Math.round( (10 * 2) / (1 - Math.pow(10, 2))*100) / 100)+')';
alert(Result);
alert(Result2);

Regards,
ben

link publish delete flag offensive edit

answered 2012-01-06 11:20:27 +0800

siva477 gravatar image siva477
57

updated 2012-01-06 11:22:11 +0800

Hi benbai,

Thanks for giving reply. I already solved the issue of String quotes in this code. But i want to declare a variable dynamically in execution time for temporary purpose. But i don't want to show it in Result.

Example:

var temp;
temp = a+b ;
temp = temp %  c;
Result = temp;


Here i already define a variable called Result , But i want declare a variable temp for temporary purpose . But In execution time ScriptEngine takes it as a undefined variable and shows Error. Can any body give me a suggestion to solve this .

With Regards,
Siva Kumar

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-01-03 05:48:07 +0800

Seen: 292 times

Last updated: Jan 06 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More