[xwiki-users] how to escape quote in velocity for javascript ?
Hello everybody, I've a simple problem. I've a text input where people can enter some text. After, I want to send that text as a param to a javascript function. However, when user types a quote (simple or double), there is a problem in my javascript syntax. I've tred to add backslash but no effect. Thanks for your help. Mathieu Canzerini.
I don't really understand if your problem is in velocity or pure javascript ? Anyway, in pure javascript you would just have to escape the single and double quotes, something like the following (I did not test it, just found it by googling) : var escapedString = inputValue.replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0"); BR, Jeremie 2012/6/11 <[email protected]>:
Hello everybody,
I've a simple problem. I've a text input where people can enter some text. After, I want to send that text as a param to a javascript function. However, when user types a quote (simple or double), there is a problem in my javascript syntax. I've tred to add backslash but no effect.
Thanks for your help.
Mathieu Canzerini.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 06/11/2012 08:43 AM, [email protected] wrote:
Hello everybody,
I've a simple problem. I've a text input where people can enter some text. After, I want to send that text as a param to a javascript function. However, when user types a quote (simple or double), there is a problem in my javascript syntax. I've tred to add backslash but no effect.
var userInput = "$!escapetool.javascript($request.userInput)";
Thanks for your help.
Mathieu Canzerini.
-- Sergiu Dumitriu http://purl.org/net/sergiu/
I've often used $escapetool.javascript($request.param) maybe that helps? paul Le 11 juin 2012 à 14:43, <[email protected]> a écrit :
Hello everybody,
I've a simple problem. I've a text input where people can enter some text. After, I want to send that text as a param to a javascript function. However, when user types a quote (simple or double), there is a problem in my javascript syntax. I've tred to add backslash but no effect.
Thanks for your help.
Mathieu Canzerini.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On Mon, Jun 11, 2012 at 5:42 PM, Paul Libbrecht <[email protected]> wrote:
Le 11 juin 2012 à 16:31, Sergiu Dumitriu a écrit :
var userInput = "$!escapetool.javascript($request.userInput)";
Actually... is there a list of such predefined variables? Or... what's the way to list them? With their class.
You mean http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Module#HVeloci... ? Hope this helps, Marius
paul _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Thank you for your response. I have already used the escapetool but he doesn't seem work : this tool adds one backslash before the quote but the script looks wrong. (onclick="function(\"param\",callback);" doesn't work) I've read this page : http://www.xwiki.org/xwiki/bin/view/FAQ/HowCanIescapeOutQuotationMarksFromAS... But whithout success ... On Mon, 11 Jun 2012 16:42:43 +0200, Paul Libbrecht <[email protected]> wrote:
Le 11 juin 2012 à 16:31, Sergiu Dumitriu a écrit :
var userInput = "$!escapetool.javascript($request.userInput)";
Actually... is there a list of such predefined variables? Or... what's the way to list them? With their class.
paul _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 06/12/2012 02:51 AM, [email protected] wrote:
Thank you for your response. I have already used the escapetool but he doesn't seem work : this tool adds one backslash before the quote but the script looks wrong. (onclick="function(\"param\",callback);" doesn't work)
What's that supposed to do? It doesn't look like semantically correct Javascript in the first place, regardless of quote escaping. Is "function" here a placeholder for a real function name, or is it really used like this in your code? You shouldn't use onclick, try this instead: http://www.prototypejs.org/api/element/observe
I've read this page : http://www.xwiki.org/xwiki/bin/view/FAQ/HowCanIescapeOutQuotationMarksFromAS... But whithout success ...
On Mon, 11 Jun 2012 16:42:43 +0200, Paul Libbrecht <[email protected]> wrote:
Le 11 juin 2012 à 16:31, Sergiu Dumitriu a écrit :
var userInput = "$!escapetool.javascript($request.userInput)";
Actually... is there a list of such predefined variables? Or... what's the way to list them? With their class.
paul
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Okay i'm going to try your suggestion. Thank you for your help. Mathieu On Tue, 12 Jun 2012 03:13:22 -0400, Sergiu Dumitriu <[email protected]> wrote:
On 06/12/2012 02:51 AM, [email protected] wrote:
Thank you for your response. I have already used the escapetool but he doesn't seem work : this tool adds one backslash before the quote but the script looks wrong. (onclick="function(\"param\",callback);" doesn't work)
What's that supposed to do? It doesn't look like semantically correct Javascript in the first place, regardless of quote escaping.
Is "function" here a placeholder for a real function name, or is it really used like this in your code?
You shouldn't use onclick, try this instead:
http://www.prototypejs.org/api/element/observe
I've read this page : http://www.xwiki.org/xwiki/bin/view/FAQ/HowCanIescapeOutQuotationMarksFromAS... But whithout success ...
On Mon, 11 Jun 2012 16:42:43 +0200, Paul Libbrecht <[email protected]> wrote:
Le 11 juin 2012 à 16:31, Sergiu Dumitriu a écrit :
var userInput = "$!escapetool.javascript($request.userInput)";
Actually... is there a list of such predefined variables? Or... what's the way to list them? With their class.
paul
participants (5)
-
Jeremie BOUSQUET -
Marius Dumitru Florea -
mathieu.canzerini@intech.lu -
Paul Libbrecht -
Sergiu Dumitriu