I tried OSRM online demo [1] and Front End source codes [2]
There we can set start and set location on text boxes. In order to set route markers between start and end we need to click on the path and drag to required point on the map.
Is there anyway to set these intermediate points dynamically using JavaScript?
Of course OSRM implements an API that can be called via JS and returns JSON routes:
https://github.com/Project-OSRM/osrm-backend/wiki/Server-api
You need to repect the API usage policy and other legal aspects.