The meta refreshes are only read at page load. If you add one after page load, or try to change one after page load, it will not work. So you can't do it with Javascript because javascript runs on the client, after page load. So you have to set the path on the serverside. If you need logic to determine between different possible paths, it will have to be on the server with a server-side language.
Example with JSP:
<%
int x = pullXfromSomewhere();
String path = "index" + x + ".jsp";
%>
<meta http-equiv="Refresh" content="3; url='<%=path%>'">