How do I get a parameter in a URL and assign it a new value?

2

Speaking of my problem, I wanted that when passing a URL with the code shown below, in the middle of the process a parameter was changed but specifically the parameter pagina that should go with value = 1 .

// FILTROS
$('#ordem').on('change', function(){
    var url = $(this).val();
    if(url != ''){
        window.open(url, '_self');
    }   
});

The URL:

http://.../busca?&area_de=50&area_at=200&ordenacao=mxvalor&pagina=2

Within the jQuery code shown, I would like every time a filter made by ordenacao is returned to page 1 or simply remove the parameter and its value, which will cause my application to automatically return to page 1 .

    
asked by anonymous 30.10.2014 / 15:27

1 answer

3

Assuming your select has URL values and just wants to change the value of the page to what it gets from this.vaue you can do this:

$('#ordem').on('change', function(){
    var url = this.value;
    if(!url) return;
    window.open(url.replace(/pagina=[\d]+/, 'pagina=1'), '_self');
});

The new part is url.replace(/pagina=[\d]+/, 'pagina=1') . If you put your HTML I can put an example too.

    
30.10.2014 / 16:10