• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to validate the apostrophe (') when using TEB and JavaScript.

New Here ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

I have a project where users need to write the time in a Text Entry Box. 

1. Users clic a speaker to hear the audio (tells the time.  For example: It is one o'clock.)

2. Then, users type that sentence time in a TEB. 

3. TEB has a variable declared (for example: writing_01 is equal to It is one o'clock)

4.  Then, a submit button checks if writing_01 is equal to the given sentence (for example: It is one o'clock).

 

Issue:

When users type the word o'clock (the submit button gives an incorrect answer). However, when I removed the apostrophe the answer is correct.

 

Problem:

Users learned to write o'clock with the apostrophe.

 

Can you suggest a proper way to handle the apostrophe?

 

Thanks.

 

 

 

Views

218

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Apr 01, 2022 Apr 01, 2022

You're welcome. Why choose a complicated approach if it can be done so easily....

Votes

Translate

Translate
Contributor , Apr 13, 2022 Apr 13, 2022

Did any of the solutions work for you?  Hope you are having a great day!

Votes

Translate

Translate
Community Expert ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

If you use the default setting for a validated TEB, and give 'one o'clock' as correct answer, it works perfectly. Why do you use an advanced action? Have a look at this post:

http://blog.lilybiri.com/text-entry-boxes-back-to-basics

Even though it is a point-and-click creation, in an advanced action you are coping with a programming language and its rules. If you need really an advanced action (which is not the case in my opinion) an easy way would be to store the correct value 'one o'clock' in another user variable and compare the associated TEB variable with that other user variable. Same workflow as is needed when checking a TEB for an empty entry:

http://blog.lilybiri.com/where-is-null-in-cp2017

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

Thank you Lilybiri.

 

I'll try the approach you suggested. I also read your articles about TEB and thanks for posting those. They are very well explained.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

You're welcome. Why choose a complicated approach if it can be done so easily....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

Ok the issue is the use of the apostrophe.

 

There are two ways that you can get around this...

 

1. Create varible(s) that will be used to represent the correct answer for a given question.
Varexamp.jpg

 

The your advance action would be like so:

 

2.  You can use a fancy escape method so that the apostrophe is able to be used in the string when doing the compare in your advanced action like so:

AdvancedActionEx.jpg

In order for the apostrophe to be used during your compare, when using and advanced action, you will need to put three '\' characters together and then your apostrophe = \\\'   This will allow the correct answer entered by the learner in the TEB It is one o'clock. to be evaluagted allowing for the correcgt ansewr to be determined.  Please keep in mind that case sensitivity plays a role...so if the learner was to enter it is one o'clock - the lowercase 'i' would then yeild a wrong answer.

 

This should get you back on track!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

The image for my answer above that goes "1. Create varible(s) that will be used to represent the correct answer for a given question.   The your advance action would be like so:" comparevar2.jpg

 

Sorry I fogot to add the image...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

Thank you OH_CP.

 

I appreciated your suggestion. I'll try that and see how it works. 

 

Sincerely,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

LATEST

Did any of the solutions work for you?  Hope you are having a great day!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources