---
title: "Customizing certificate selection"
description: "How to customize the text shown for each certificate in a Web PKI selection list using selectOptionFormatter and the certificate properties."
canonical: "https://docs.lacunasoftware.com/en-us/articles/web-pki/cert-select"
locale: "en"
product: "Web PKI"
last_updated: "2026-10-12"
---

# Customizing certificate selection

You can customize the text that will be displayed for each certificate using any of the [Certificate properties](https://docs.lacunasoftware.com/en-us/articles/web-pki/cert-properties)
returned by Web PKI for each certificate:

```js
function onWebPkiReady() {
	pki.listCertificates({
		selectId: 'certificateSelect',
		selectOptionFormatter: getCertText
	});
}

function getCertText(cert) {
	return cert.subjectName + ' (issued by ' + cert.issuerName + ')';
}
```

The same applies if you are manually processing the certificates array instead of using `selectId` and `selectOptionFormatter`:

```js
function onWebPkiReady() {
	pki.listCertificates().success(function (certs) {
		var select = $('#certificateSelect');
		for (var i = 0; i < certs.length; i++) {
			var cert = certs[i];
			select.append(
				$('<option />').val(cert.thumbprint).text(getCertText(cert))
			);
		}
	});
}

function getCertText(cert) {
	return cert.subjectName + ' (issued by ' + cert.issuerName + ')';
}
```

For instance, to show the **expiration date** along with the subject name:

```js
function getCertText(cert) {
	return cert.subjectName + ' (expires on ' + cert.validityEnd.toLocaleDateString() + ')';
}
```

We can also show the subject and issuer plus an `[EXPIRED]` prefix on the certificates that are expired:

```js
function getCertText(cert) {
	var text = cert.subjectName;
	if (new Date() > cert.validityEnd) {
		text = '[EXPIRED] ' + text;
	}
	return text;
}
```

> **Tip**
>
> We recommend always using at least one additional property besides the subject name in order to help users that have
> two or more certificates with the same subject name (in other words, don't just do `return cert.subjectName;`)

## Validating the selected certificate

This section has been moved to a separate article: [Certificate pre-validation](https://docs.lacunasoftware.com/en-us/articles/web-pki/cert-validation)

## Sorting the certificates

This section was removed because Web PKI now automatically returns the certificates sorted by `subjectName`.

> **Note**
>
> If this is not happening on your web application, update the Web PKI JavaScript library

**Demos and samples**

- Live demo: [Your certificates in the browser](https://try.lacunasoftware.com/en/web-pki/certificates-in-the-browser)
- List the user's certificates with Web PKI: [.NET](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/dotnet/mvc/PkiSuiteAspNetMvcSample/Controllers/ListCertJQueryController.cs) · [Java](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/java/springmvc/src/main/java/com/lacunasoftware/pkisuite/controller/ListCertJQueryController.java) · [Node.js](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/nodejs/expressmvc/routes/list-cert-jquery.js) · [Python](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/python/flask/sample/views/list_cert_jquery.py) · [Ruby](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/ruby/rails/app/controllers/list_cert_jquery_controller.rb)
- Read a certificate's details with Web PKI: [.NET](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/dotnet/mvc/PkiSuiteAspNetMvcSample/Controllers/ReadCertJQueryController.cs) · [Java](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/java/springmvc/src/main/java/com/lacunasoftware/pkisuite/controller/ReadCertJQueryController.java) · [Node.js](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/nodejs/expressmvc/routes/read-cert-jquery.js) · [Python](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/python/flask/sample/views/read_cert_jquery.py) · [Ruby](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/ruby/rails/app/controllers/read_cert_jquery_controller.rb)
