Getting student name to print first name, last name

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?

Discussion (7)

I have the same problem

@aoswald, you are responding to a 12 year old message.

People can help you better if you give more information. What version of Lectora are you using, for starters?

figured it out - thanks

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

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.

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.

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