Tengo problemas para recuperar un valor seleccionado de un <select>
o combo de html desde VB.NET, tengo 3 <div>
cada uno con cierta función y para que aparezca solo el <div>
que seleccione el usuario oculto los otros dos.
El problema es que no puedo obtener el valor que se ha seleccionado. Cuando intento recuperar la variable de servidor "cd", obtengo el ultimo valor del switch de la función JavaScript, es decir cd="ciudad3"
y no el que seleccione.
<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
Lo he intentado con request.Form("sucursal")
, pero no me obtiene nada.