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

More
3 years 11 months ago #96080 by startx25
startx25 created the topic: insert javascript code in a question with { and } in source
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 ?

Please Log in to join the conversation.

More
3 years 11 months ago #96093 by cshaw
cshaw replied the topic: insert javascript code in a question with { and } in source
Do you have to wrap it with <script></scrip> tags?

Please Log in to join the conversation.

More
3 years 11 months ago #96099 by TMSWhite
TMSWhite replied the topic: insert javascript code in a question with { and } in source
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:
$("#answer21812X30X985").keypress(function(event) {
var reg = new RegExp("[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]{ 5, }", "g");
alert(reg.test($("#answer21812X30X985").val()));
}

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.