Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

insert javascript code in a question with { and } in source

  • startx25
  • startx25's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
10 years 10 months ago #96080 by startx25
Hi,

I am trying to check a textarea during a keypress event. (looking for 5 consonnes)

i want to use regex to do that so :


.....
$("#answer21812X30X985").keypress(function(event) {
var reg = new RegExp("[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]{5,}", "g");
alert(reg.test($("#answer21812X30X985").val()));
}

but when i insert this code, limesuvey replace in generated source with this :

var reg = new RegExp("[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]<span style='background-color: #eee8aa;'><span title='Pas une expression valide; Expression mal terminée - attendait une constante ou variable' style='border-style: solid; border-width: 2px; border-color: red;'>5</span>, </span>", "g");

so how can i insert symbol { and } in source question ?
The topic has been locked.
More
10 years 10 months ago #96093 by cshaw
Do you have to wrap it with <script></scrip> tags?
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #96099 by TMSWhite
Expression Manager processes anything between curly braces unless there is whitespace immediately after the opening curly brace and before the closing one. So, add that whitespace:
Code:
$("#answer21812X30X985").keypress(function(event) {
var reg = new RegExp("[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]{ 5, }", "g");
alert(reg.test($("#answer21812X30X985").val()));
}
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose