Basically I have a url that needs to be changed dinamically to call on another functions, so for example I have "index/buscasimples/finalidade/1/filtro/1/", and when a specific button is pressed, I need to replace the part where it is "filtro/1/" for another one. The problem is that this number "/1/" can vary, from 1 to 3, so I'll probably need an if to do the work. But I want to know if there is another way that could help me...
To be clearer, the code is like this
$('#filtro').change(function(e) {
e.preventDefault();
var filtro = $('#filtro option:selected').val();
var urlAtual = window.location.href;
var url = urlAtual.replace('/buscasimples/','/buscafiltrada/');
url += 'filtro/'+filtro+'/';
window.location = url;
})
This function changes the url and put on the "filtro" that is needed, and work fine for the first time. But then when the proccess is repeated, there'll be 2 "filtro" in the url, so I want to replace the "filtro" and the number that is next to it, but this number can be 1, 2 or 3 as I said. There's some native jquery function that can replace one character whatever they are like "replace.('filtro/@/')" or something? Sorry for long question, I got that application already made and I'm trying to deal with it haha Thanks!!