My suggestion is as follows: create a span
shortly after select
( span
does not interfere with anything in the page layout, it will only be used to receive a form where op
will be sent %). It will look 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 no onchange
will be called a redir
function by passing the value of option
selected.
Now insert the function into 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();
}
When firing 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 will be submitted with the op
field via POST.
In this way you can retrieve the cod
and op
values in ASP with:
<%
cod = request("cod")
op = request("op")
%>