Lectora Tips #3: Replacing Feedback Commas Part II

We already discussed how easily Feedback Commas can be replaced in you Lectora eLearning course. But what happens when your feedback answer contains a comma you would like to keep? Take a deep breath, we can help!

Instead of replacing all commas in your question answers, we want to replace only the commas with a space after them. This will ensure that any commas included in your answer will not be replaced.

So, replace this code:
str = str.replace(“,”, ” – “);

With this code:
str = str.replace(/, /g, “## “);
str = str.replace(/,/g, ” – “);
str = str.replace(/##/g, “, “);

The final should look something like this: 

<script language=”JavaScript”>
function formatAnswer() {
var nameArray = new Array();
var str = VarQuestion_0012.getValue();
str = str.replace(/, /g, “## “);
str = str.replace(/,/g, ” – “);
str = str.replace(/##/g, “, “);
text39673.actionChangeContents(str,’alignleft’,’1′);
}
var t=setTimeout(formatAnswer,2000);
</script>

Of course, you will need to replace the Lectora Question variable and answer text field HTML Name with the applicable ones in your question(s).Again, the Lectora variable for Question 12 is “Question_0012.For this code, add “Var” in front of the variable name.

Once more, the answer text field’s HTML Object Name is “text39673”. Use the HTML Name found in the field’s properties window. If you don’t see the HTML Name in the properties window, open Preferences and in the General tab select “Show HTML-published object names in object properties”.

You’ve got it–no sweat!!

By LHT Learning
| January 18, 2013
Share on facebook
Share on twitter
Share on linkedin
Archives