-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
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
Asked: 2012-01-03 05:48:07 +0800
Seen: 292 times
Last updated: Jan 06 '12