Welcome, Guest
Username: Password: Remember me

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

insert javascript code in a question with { and } in source 11 months 3 days ago #96080

  • startx25
  • startx25's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 50
  • Karma: 0
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 administrator has disabled public write access.

insert javascript code in a question with { and } in source 11 months 3 days ago #96093

  • ohvelma
  • ohvelma's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 20
  • Karma: 0
Do you have to wrap it with <script></scrip> tags?
The administrator has disabled public write access.

insert javascript code in a question with { and } in source 11 months 2 days ago #96099

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
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()));
}
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.152 seconds
Donation Image