This article applies to the "Apply" tab on a payment page.
If you don't want to think too hard about how to apply your payment to invoices - and who does? - simply select the "Auto-apply" checkbox in the top left corner of the invoice table.
This will automatically apply as much of the payment as possible to invoices in order from most overdue to least overdue. It will continue to apply the maximum amount to each invoice until either the payment runs out or there are no invoices left to pay, in which case you will have some payment left over to apply to future invoices. Simply click "Apply Payment" at the bottom of the table when you are done.
Example page: