Remove the armrest from the chair by removing the screws that attach it to the bottom or side of the chair.
Remove the staples that hold the fabric to the armrest by using a needle nose pliers or staple remover. Then pull off the foam padding under the fabric. Use a paint scraper to remove any foam debris stuck to the armrest.
Measure the size of your replacement foam by placing the armrest face down on the piece of foam and drawing a line around the armrest. Then use a razor blade or box cutter to cut the foam to the size of the armrest.
Glue the foam to the armrest using an industrial-strength glue. Allow to dry.
Use a similar method to measure and cut the upholstery fabric; lie the armrest with attached foam face down on the piece of fabric, but this time wrap the fabric around the armrest to measure how much you'll need. Before cutting the fabric to size, be sure the pattern on the fabric is lined up in the desired position. When you do the cutting, err on the large side; it's better to have too much fabric than too little when you go to wrap it around the armrest.
Spray an adhesive on the foam and place the fabric over the top to bond the fabric and foam. Wrap the fabric around the armrest and staple it to the underside of the armrest. Cut off any excess fabric from the underside once the staples are in place.
Screw the armrest back on the chair.