Link to home
Start Free TrialLog in
Avatar of limmontreefree
limmontreefreeFlag for Spain

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('uno').className = "activo";
        }
     if (<%=Session("MenuOption")%> = "two") {
         document.getElementById('dos').className = "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('uno').className = "activo";
        }
     if (one = "two") {
         document.getElementById('dos').className = "activo";
        }
<




ASKER CERTIFIED SOLUTION
Avatar of Eyal
Eyal
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or better...

    <script type="text/javascript">
    <%if (Session("MenuOption") = "one") then
        response.write "document.getElementById('uno').className = 'activo';"
        end if
     if(Session("MenuOption") = "two") then
         response.write document.getElementById('dos').className = 'activo';"
end if
       %>
Avatar of limmontreefree

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('uno').className = "activo";
        }
     if ("<%=Session("MenuOption")%>" == "two") {
         document.getElementById('dos').className = "activo";
        }
</script>

your second option don´t work in my code, i don't know why...