Hi,
If it works OK with the charger connected but not when on battery power only, then most probably the battery is failing and needs to be replaced.
Here’s a [https://www.youtube.com/watch?v=GhB3rUlleh4|video] that shows how to access the battery.
Battery supplies are available online. Just search for ''HTC Desire 500 battery'' to get results.