To travel from Hungary to Croatia by train, buy your tickets online from Hungarian Railways MAV START or from a station in Hungary. A number of offers is available, for instance Sparschiene tickets from 19€ for the single trip Budapest - Zagreb. Online tickets have to be printed from ticket machines at stations in Hungary!
There are two daily express trains between Budapest and Zagreb and night trains from Budapest to Rijeka and Split during the summer months.
If you want to travel from Croatia to Bosnia-Herzegovina by train, buy your ticket locally at a station. There are no online tickets available.
The only international service to Bosnia-Herzegovina is the train from Zagreb to Sarajevo. Unfortunately, this connection has been suspended in December 2016.
All other international lines have been closed for several years.
At the moment, it is only possible to get to Bosnia-Herzegovina by bus.