Jump to content

Formatting Multiple selections


AmyB

Recommended Posts

I need to know how to build a rule for the following:

 

4 optional fields

Not prefilled

Each field 2 characters long (last 2 digits of a year, such as 09, 10, 11, 12)

 

1. If field is chosen, input " ’ " and addend to end of Name field

2. If single, end.

3. If multiple, place " , " between multiples

4. No commas on last entry

 

e.g. Amy Brown P ’10, ’11, ’12

 

The above example shows my name, "P" for Parent, and the graduating years of my children from a school. There will be 4 optional fields to choose graduating years from a pull down menu.

 

So if you select:

1 year, you'll see: Amy Brown P ’10

2 years, you'll see: Amy Brown P ’10, ’11

3 years, you'll see: Amy Brown P ’10, ’11, ’12

4 years, you'll see: Amy Brown P ’10, ’11, ’12, ’13

 

Any feedback for how to write a rule for this would be greatly appreciated!

Link to comment
Share on other sites

  • 1 month later...

I think I was on vacation when this post went up. I'm guessing you already solved your problem, but since I like to sharpen my JS skills, I'll post my solution anyway. :)

 

//Replace Field names with your field names for first 6 lines
var Grad1 = Field("1stChild");
var Grad2 = Field("2ndChild");
var Grad3 = Field("3rdChild");
var Grad4 = Field("4thChild");
var UserTitle = Field("Title");
var UserName = Field("Name")

//Edit/add case values as necessary
switch (UserTitle) {
  case "Parent": 
     var TitleCode = "P";
     break;
  case "Teacher": 
     var TitleCode = "T";
     break;
  case "Volunteer": 
     var TitleCode = "V";
     break;
  default: 
     var TitleCode = "";
}

var UserGrads = new Array();
if (Grad1 != "") UserGrads.push(Grad1);
if (Grad2 != "") UserGrads.push(Grad2);
if (Grad3 != "") UserGrads.push(Grad3);
if (Grad4 != "") UserGrads.push(Grad4);


function sortNumber(a, b) {
  return a - b;
}

UserGrads.sort(sortNumber);

var AllGrads = UserGrads.join(", '");

if (AllGrads != "") {
  var UserInfo = UserName + " " + TitleCode + " '" + AllGrads;
} else {
  var UserInfo = UserName + " " + TitleCode;
}

return UserInfo;

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...