HPs, similar to Dell, often use a third wire communication with the power adapter. That allows the computer to know what size power adapter is plugged in.
Your problem could be one of two problems. The power adapter could be bad. In which case, just try another one. Or, your motherboard could be damaged. If that is that is the case, it’s probably the power jack.
The easiest thing to try here is a different power adapter. You might also be able to go into BIOS setup and it might tell you if it recognizes the power adapter or not. I think HP is a bit more limited in this regard though. Tapping F10 during power on usually gets you in to BIOS setup for HP.
Whatever it is, either the power adapter or motherboard is not delivering enough power to charge the battery when the computer is on.
There is an off chance the battery is just bad and taking too much power to charge. But I really think this sounds unlikely with your description. You’ve indicated the battery charges when the power is off, and I am assuming it runs on battery properly with a reasonable amount of run time.
2... and your question is... – Tetsujin – 2018-05-27T11:40:45.340