Getting student name to print first name, last name

domanjem
Community Member Posts: 19 ☆ Roadie ☆
I am trying to have a certificate print with the students name. When I do it prints last name, first name. I want it the opposite. Is there a way to do this besides having the user enter the info and capturing it using variables?I am trying to have a certificate print with the students name. When I do it prints last name, first name. I want it the opposite. Is there a way to do this besides having the user enter the info and capturing it using variables?
Comments
-
How did you do it? It'd be nice if you provided the details on how you made it happen so that if others stumble across your request they can get the assistance too. I have always done it with JavaScript, but it'd be interesting to learn how you did it.Andrew R.
Developing content since 2010 using a mixed bag of tools. -
used three actions. the first was
AICC_Student_Name.value = AICC_Student_Name.getValue()
the 2nd and this is not original with me. I found it here but can't remember the name of the guy who posted it.
// override AICC_Update
AICC_Student_Name.update = function(){};
// reformat the student name
var studentName = AICC_Student_Name.value;
studentName = studentName.replace(/,/g," ");
studentName = studentName.replace(/\s+/g," ");
var studentNames = studentName.split(" ");
if (studentNames.length > 3)
AICC_Student_Name.value = studentNames[1] + " " + studentNames[2] + " " + studentNames[0] + " " + studentNames[3];
else if (studentNames.length > 2)
AICC_Student_Name.value = studentNames[1] + " " + studentNames[2] + " " + studentNames[0];
else if (studentNames.length > 1)
AICC_Student_Name.value = studentNames[1] + " " + studentNames[0];
And the third was just to "Change Contents" in the text box where the name goes.
It works great -
Exactly what I do. Great job on figuring it out.
Providing the answer to your own question is the best learning that can be done, the second best is learning from others who have already figured it out..
Thanks for sharing.Andrew R.
Developing content since 2010 using a mixed bag of tools. -
I wonder why studentName isn't just split by the comma? I mean that's why the name is saved in this format: to make it easy to split last name and first names. The script above removes the comma and then mainly guesses what parts of the remaining array might be part of the last name.
It says: If the name contains more than 3 parts put them together as
studentNames[1] + " " + studentNames[2] + " " + studentNames[0] + " " + studentNames[3];
= part 2 part 3 part 1 part 4
For "Van Horn, Keith Adam" this would mean: "Horn Keith Van Adam"
For "Van Horn, Keith" it's "Horn Keith Van"
In the end the only case where the script will work reliably is "if (studentNames.length > 1)", i.e. if there are 2 parts ... When you split the name by the comma it cannot have more than 2 items.
studentNames[0] will contain the last name, with all Des, Ofs, Vans, Vons, ys or II.s
studentNames[1] will contain the first and all middle names
Categories
- 35.8K All Categories
- 109 ✫ Announcements
- 33.1K Lectora®
- 31.1K Lectora Discussions
- 28.9K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 22 ELB Learning Content
- 22 ELB Learning Content Discussions
- 321 CenarioVR®
- 188 CenarioVR Discussions
- 133 CenarioVR Feature Requests
- 41 Rockstar Learning Platform®
- 38 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 47 ReviewLink®
- 47 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 934 All Things eLearning
- 36 eLearning Development
- 546 Learning Management System (LMS) Integration
- 332 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products