Disabling period entry in text box | XM Community
Skip to main content
Solved

Disabling period entry in text box


bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Level 6 ●●●●●●
  • 639 replies
I'm trying to disable periods in the name field of a form. I've been googling for some code to update and I'm not having luck with it working. I don't want people to enter periods because it is causing problems later on in my processes. I am trying to reference the text box in QID1, which happens to be the first form field. Here's the code I'm trying to reuse from other sources: Qualtrics.SurveyEngine.addOnload(function() { /*Place your JavaScript here to run when the page loads*/ $('QR~QID1~1~TEXT').keypress(function(key) { if(key.charCode == 190 || key.charCode == 110) return false; }) }); Any advice on what I can do so that the period and number pad decimal keys are disabled for this form field? Thank you in advance!

Best answer by TomG

Change .InputText to .InputText:first
View original

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • July 2, 2018
``` jQuery("#"+this.questionId+" .InputText").on('input', function() [ this.value = this.value.replace(/\\./g, ""); }); ``` Replace the [ with a { ... I had to change it to avoid the 'Access Denied' error.

bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Author
  • Level 6 ●●●●●●
  • 639 replies
  • July 2, 2018
@TomG this is working but it blocks periods for all of the fields in my form. I tried a few things to point it just to the first field in the form but that seemed to break it. (e.g. changing this.questionID to 'QR~QID1~1' and '#"+this.questionID+'~1'+".InputText") My form is: QR~QID1~1 = Name QR~QID1~2 = Email QR~QID~3 = Confirm email So I need respondents to be able to put periods into their email address. Is it possible to apply this rule to just one part of the form or should I break name and email confirmation into separate questions so the code will work?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • Answer
  • July 2, 2018
Change .InputText to .InputText:first

bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Author
  • Level 6 ●●●●●●
  • 639 replies
  • July 3, 2018
Thanks @TomG! Works like a charm.

Leave a Reply