My suggestion is this: create a span
shortly after the select
(the span
does not interfere with anything in the page layout, will be used only to receive a form from which will be sent the value of op
). Will stay like this:
<select onchange="redir(this.value)" id="sel">
<option value="?cod=11&op=1">opção 1</option>
<option value="?cod=21&op=2">opção 2</option>
<option value="?cod=31&op=3">opção 3</option>
</select>
<span id="tempform"></span>
Note that in the onchange
a function will be called redir
passing the value of option
selected.
Now enter the function on the page:
function redir(i){
// pega o valor do select e separa em grupos cod=X e op=X
var params = i.match(/\?(.+)&(.+)/);
// pega cod=X
var cod = "?"+params[1];
// pega apenas a parte numérica de op=X
var op = params[2].match(/\d+/)[0];
// monta o formulário para ser enviado com o valor de op
// note que o formulário não aparecerá na página com display: none
var form = '<form style="display: none;" method="post" action="'+location.href+cod+'">'
+'<input name="op" value="'+op+'">'
+'</form>';
// insere o formulário no span
document.getElementById("tempform").innerHTML = form;
// faz o submit do formulário
document.querySelector("#tempform form").submit();
}
By firing the onchange
of select
, the page will be redirected to itself in this way:
pagina.asp?cod=valor_no_option
At the same time the form created by the script with the field will be submitted op
via POST.
This way you can recover the values cod
and op
in ASP with:
<%
cod = request("cod")
op = request("op")
%>
Have you tried Ajax or
history.pushState
?– Valdeir Psr
could just use
this.value
instead ofoptions[selectedIndex].value
.– Sam
Using PHP to get the values?
– Sam
It is Asp and it takes the same pag for Cod and reorders the menu with op=x. DVD: I switched to onchange="Location = this.value" but the parameter &op=x continues to appear. I need to include some more command?
– Geo
@Valdeirpsr, I read now about history.pushState, but unfortunately pgm in Asp is not Html5. But it will be useful for me in another php and Html5 project. Thank you for your attention.
– Geo
The tip I mentioned was not to solve the problem, it was just to make it simpler :D... I will analyze the code...
– Sam