Getting student name to print first name, last name

domanjem
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

  • aoswald
    aoswald Community Member Posts: 119 ♪ Opening Act ♪
    I have the same problem
  • carlfink
    carlfink Community Member Posts: 954 ✭ Legend ✭
    @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?
  • aoswald
    aoswald Community Member Posts: 119 ♪ Opening Act ♪
    figured it out - thanks
  • andrew-robertson
    andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
    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.
  • aoswald
    aoswald Community Member Posts: 119 ♪ Opening Act ♪
    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
  • andrew-robertson
    andrew-robertson Community Member Posts: 185 ☆ Superstar ☆
    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.
  • timk
    timk Community Member Posts: 1,199 ♦ Idol ♦
    edited September 18, 2021
    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