Hi @gomezvalverde
Please check this thread regarding PHP and Javascript: http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming.
Basically, you need to add the PHP code in your JS code. To get the gallery values, please check this page: https://www.advancedcustomfields.com/resources/gallery/.
I hope this helps.