limmontreefree
asked on
javascript and session variable
hello all,
I have a website made ¿¿with visual studio 2010. I use a javascript function to activate a menu option, I want to activating the javascript in function of a session variable.
in the default.aspx.vb load event
Dim strQueryOutlet As String = Request.QueryString.Get("O ") 'Si el valor es 1 es Outlet, si es O es promocion.
If strQueryOutlet Is Nothing Then
blnEsOutlet = True
ElseIf strQueryOutlet = "1" Then
blnEsOutlet = True
ElseIf strQueryOutlet = "0" Then
blnEsOutlet = False
Else
blnEsOutlet = True
End If
If blnEsOutlet Then
Session("EsOutlet") = "1"
Session("MenuOption") = "one"
Else
Session("EsOutlet") = "0"
Session("MenuOption") = "two"
End If
In the default.aspx
<script type="text/javascript">
if (<%=Session("MenuOption")% > = "one") {
document.getElementById('u no').class Name = "activo";
}
if (<%=Session("MenuOption")% > = "two") {
document.getElementById('d os').class Name = "activo";
}
</script>
when I run the proyect...the default.aspx dynamic show... and the two if are executed...
and the two menu option are selected, and this is a mistake...
<script type="text/javascript">
if (one = "one") {
document.getElementById('u no').class Name = "activo";
}
if (one = "two") {
document.getElementById('d os').class Name = "activo";
}
<
I have a website made ¿¿with visual studio 2010. I use a javascript function to activate a menu option, I want to activating the javascript in function of a session variable.
in the default.aspx.vb load event
Dim strQueryOutlet As String = Request.QueryString.Get("O
If strQueryOutlet Is Nothing Then
blnEsOutlet = True
ElseIf strQueryOutlet = "1" Then
blnEsOutlet = True
ElseIf strQueryOutlet = "0" Then
blnEsOutlet = False
Else
blnEsOutlet = True
End If
If blnEsOutlet Then
Session("EsOutlet") = "1"
Session("MenuOption") = "one"
Else
Session("EsOutlet") = "0"
Session("MenuOption") = "two"
End If
In the default.aspx
<script type="text/javascript">
if (<%=Session("MenuOption")%
document.getElementById('u
}
if (<%=Session("MenuOption")%
document.getElementById('d
}
</script>
when I run the proyect...the default.aspx dynamic show... and the two if are executed...
and the two menu option are selected, and this is a mistake...
<script type="text/javascript">
if (one = "one") {
document.getElementById('u
}
if (one = "two") {
document.getElementById('d
}
<
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Eyal:
the first option don't wok when i run it raise the error:
run time error executing Jcript, it can't be assign a '[string]'
and this sentence has light the bulb, (i dont want assing nothing i only want to compare) and then i thy this... and now it works fine
<script type="text/javascript">
if ("<%=Session("MenuOption") %>" == "one") {
document.getElementById('u no').class Name = "activo";
}
if ("<%=Session("MenuOption") %>" == "two") {
document.getElementById('d os').class Name = "activo";
}
</script>
your second option don´t work in my code, i don't know why...
the first option don't wok when i run it raise the error:
run time error executing Jcript, it can't be assign a '[string]'
and this sentence has light the bulb, (i dont want assing nothing i only want to compare) and then i thy this... and now it works fine
<script type="text/javascript">
if ("<%=Session("MenuOption")
document.getElementById('u
}
if ("<%=Session("MenuOption")
document.getElementById('d
}
</script>
your second option don´t work in my code, i don't know why...
<script type="text/javascript">
<%if (Session("MenuOption") = "one") then
response.write "document.getElementById('
end if
if(Session("MenuOption") = "two") then
response.write document.getElementById('d
end if
%>