Losing an erection during foreplay is a common experience among men of different ages. Do not break up with your partner because he keeps losing erections during foreplay. Whether it is his or subsequent time to have sex, make sure you understand the situation at hand.
First and foremost, losing your erection doesn't mean that the woman is less attractive. Continue kissing and caressing him. Indulge in continued foreplay and he will regain his erection in a matter of minutes. There are some men who tend to lose erections while wearing condoms.
If you are sure of his status and you are not worried about Pregnancy or STD's, after talking to him deeply about the matter, then you can opt to leave protection.
Although this could be the last option after everything else has failed, it could work for you in the long run. You can also try penetration on top of her.
Just continue thrusting your semi-erect penis while on top of her and you will surely get an erection in the long run. If you have tried everything within your means and he keeps losing his erection then it can be a good decision to seek medical attention with immediate effect.