I have problems to recover a selected value of a <select>
or combo of html from VB.NET, I have 3 <div>
each with a certain function and so that only the <div>
that the user selects hidden appears two.
The problem is that I can not get the value that has been selected. When I try to retrieve the server variable "cd", I get the last value of the JavaScript function switch, that is, cd="ciudad3"
and not the one that I select.
<script>
function myFunction() {
@code dim var cd As String end code
var x = document.getElementById("sucursal").value;
switch (x) {
case "":
alert("seleccion incorrecta")
break;
case "ciudad1":
document.getElementById("ciudad2").style.display = "none";
document.getElementById("ciudad3").style.display = "none";
document.getElementById("ciudad1").style.display = "block";
@code cd="ciudad1" end code
break;
case "ciudad2":
document.getElementById("ciudad1").style.display = "none";
document.getElementById("ciudad3").style.display = "none";
document.getElementById("ciudad2").style.display = "block";
@code cd="ciudad1" end code
break;
case "ciudad3":
document.getElementById("ciudad2").style.display = "none";
document.getElementById("ciudad1").style.display = "none";
document.getElementById("ciudad3").style.display = "block";
@code cd="ciudad1" end code
break;
}
}
</script>
<div class="panel panel-primary">
<div class="panel-heading">
<h4>
<span class="glyphicon glyphicon-th"></span>
Directorio
</h4>
</div>
<div class="panel-body">
<form method="post" role="form">
<div class="form-group">
<label for="sel1">Sucursal</label>
<select class="form-control" id="sucursal" name="sucursal" onchange="myFunction()">
<option value="">-- Seleccione una opción --</option>
<option value="ciudad1">Ciudad uno</option>
<option value="ciudad2">Ciudad dos</option>
<option value="ciudad3">Ciudad tres</option>
</select>
</div>
</form>
</div
</div>
@code
'Dim x As String = Request.Form("sucursal")
Try
Dim cn = ConfigurationManager.ConnectionStrings("directorio").ConnectionString
Dim conexion As New SqlConnection(cn)
Dim cmd As New SqlCommand()
cmd.Connection = conexion
cmd.CommandText = "SELECT * FROM directorio WHERE idcIUDAD = '"& cd &"' ORDER BY puesto DESC"
conexion.Open()
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then End code
<div class="alert alert-success" role="alert" >@dr.Item("Puesto")</div>
<strong>Nombre.:</strong><div>@dr.Item("nombre")</div>
<strong>Telefono.:</strong><div>@dr.Item("telefono")</div>
<strong>Extensión.:</strong><div>@dr.Item("ext")</div>
<strong>E-mail.:</strong><div>@dr.Item("correo_electronico")</div>
@code
End If
end code
@Code Catch ex As Exception
MsgBox("Error" + ex.ToString(), MsgBoxStyle.Critical, "Fónix")
End Try
End Code
I've tried it with request.Form("sucursal")
, but you do not get me anything.