Copy link to clipboard
Copied
Hi, is it possible to sort a list of names alphabetically in a form field. I don't want to use the list function, as the names change daily and I don't want to have to edit the form for my staff every time a new name appears. Is there a script that would automatically sort the names alphabetically in the form field.
Thanks
Copy link to clipboard
Copied
You can use this code as the field's custom validation script:
if (event.value!="") {
var names = event.value.split("\r");
names = names.sort(function(a,b) {if (a<b) return -1; if (a>b) return 1; return 0});
event.value = names.join("\r");
}
And setting up a calculated value is not difficult at all... If you provide more details I could help with that as well.
Copy link to clipboard
Copied
You need to better explain your set-up, but yes, it is possible.
Does this field have a calculated value, or a user-entered one? How are the names separated from each other?
Copy link to clipboard
Copied
Thanks for replying.
I have a multi-line form box that has names in a list format, one underneath another, which are separated by a return. e.g.
Adan Smith
Eve Jones
Jane Doe
Etc.
The field has no calculated value, as I couldn't get my head round how it would work.
I'd like the form field to automatically sort the names alphabetically by their first names, is this possible using a script?
The form was previously in MS Word, but the staff keep wrecking the layout, so was hoping that a PDF form would stop this happening.
Thanks
Copy link to clipboard
Copied
You can use this code as the field's custom validation script:
if (event.value!="") {
var names = event.value.split("\r");
names = names.sort(function(a,b) {if (a<b) return -1; if (a>b) return 1; return 0});
event.value = names.join("\r");
}
And setting up a calculated value is not difficult at all... If you provide more details I could help with that as well.
Copy link to clipboard
Copied
Thank you so much, that works perfectly, amazing.
Copy link to clipboard
Copied
Hello,
I batch scan hundreds of invoices into a scan folder. I need/want to use Adobe Acrobat DC to sort those hundreds of invoices alphabetically, is that possible? Please advise what steps I need to follow in Adobe in order to sort the batch scanned invoices alphabetically.
Copy link to clipboard
Copied
This is a new question. Please ask it on a new thread.
Copy link to clipboard
Copied
Hi, I have tried to type the advised code into the java script but its not working.
I am trying to do the same thing...
a list of names first name and last name underneath one another and I would like to sort them alphabetically using a java script.
I went into mouse up function, enter java script and copied this
if(event.value!=“”){
var names = event.value.split(“\r”);
names = names.sort(function(a,b){if(a<b)return -1; if(a>b)return 1; return0});
event.value=names.join(“\r”);
}
but it tells me that there is a syntax error in the second line "var names....".
Any advise would be majorly appreciated. I am a complete newbie with javascript so would be grateful for some advise.
Thank you
Copy link to clipboard
Copied
Use " not ” for text strings.
Copy link to clipboard
Copied
I am really sorry...what do you mean by that? What do I need to change within my code? Or do I need to put it somewhere else? I put it into Form Field "Action", "Mouse up", "Java Script"
Is that wrong for this code? Still trying to get my head around the whole Java script 🙈
Copy link to clipboard
Copied
Replace ” with " in your script.
Copy link to clipboard
Copied
Perfect. Thank you soooo much. It accepted the code now. Just sorting the names isn't working 🙈.
Copy link to clipboard
Copied
Don't use Word for code! Only a plain-text editor, like Notepad++.
Copy link to clipboard
Copied
I am using acrobat DC and a form field. Is that wrong?
Copy link to clipboard
Copied
The issue is with the code. As Bernd pointed out, you've used an incorrect character, namely the curly quotes. You can only use straight quotes in your code.
Copy link to clipboard
Copied
I see. What a silly mistake. Thank you for pointing this out. It is taking the code now but unfortunately it is not sorting my name list alphabetically. 🙈
Copy link to clipboard
Copied
Fixed it. I needed to put it under Calculations - Java Script not Actions. Thank you so much for your help.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more