Setting session varible to value of dropdown combo

I am trying to set a session variable to the value of a drop down combo box.  I have posted teh complete code below, but in essence I have tried setting the value to using the "OnChange" event of the combo box, the "OnClick" event of a button, but to no avail.  The code below is not the complete code, just a page I created to test with.

What I woudl really like is for the "Submit" button to be disabled until they select an option from the drop down, but that code does not seem to work either.   Any help would be greatly appreciated.

[code]
<%
@ Language=VBScript
%>
<!-- #include file="connect.asp" -->
<head>
  <title></title>
    <META http-equiv="Content-Script-Type" content="text/vbscript">
    <script type="text/vbscript">
      sub Sub_Value()
          session("ic_sub_code") = document.getElementsByName('cboSubs').Value
          Response.Write "Sub Code: " & session("ic_Sub_Code")
          if mSubValue = "0" then
              Sub.Disabled = True
          else
              Sub.Disabled = False
          end if
      end sub
    </script>
</head>

<body>
<%
if request("mode") <> "5" then
    query = "SELECT DISTINCT [INDIV-NAME], [INDIV-CODE] FROM qry_RosterList ORDER BY [INDIV-NAME]"
    set oRs = con.execute(query)
%>
    <form name="Substitute" method="post" action="testing.asp">  ' testing.asp is this form...
    <table cellspacing="0" cellpadding="0" border="0" width="80%">
        <tr>
            <td align="right">Select a Substitute:</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td><select name="cboSubs" size="1">
                <option value="0">Select a Substitute...</option>

    <%

    Do while not oRS.EOF
    response.Write "<option value='" & oRS("INDIV-CODE") & "'>"
    response.Write oRS("Indiv-name") & "</option>"
    oRS.MoveNext
    Loop
    oRs.close


    %>
            </td>
        </tr>
        <tr>
            <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <input type="hidden" name="mode" value="5">
            <td align="right"><INPUT type="Button" value="Submit" Name="Sub" onclick="Sub_Value();" disabled=true/></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td align="center"><a href="default.asp">Home</a></td>
        </tr>

    </table>
    </center>
    </form>
<%
else
    Response.Write "Sub Code: " & session("ic_sub_code")
end if
%>
[/code]
ggreweAsked:
Who is Participating?
 
GawaiCommented:
better you use cookies instead of session
0
 
GawaiCommented:
<select name="cboSubs" onChange="document.Substitute.cboSubs.options[selectedIndex].value=<%=session("ic_sub_code")%>>
0
 
ggreweAuthor Commented:
Thanks gawai, I modified that code, but when I submit, the

[code]
Response.Write "Sub Code: " & session("ic_sub_code")
[/code]
at the bottom of the code still does not display the value.  Any ideas?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ggreweAuthor Commented:
This does not seem to work either.  

<select name="cboSubs" onChange=<%session("ic_sub_code")%> = document.Substitute.cboSubs.options[selectedIndex].value">
0
 
CWS (haripriya)Commented:
use 'Id' instead of 'name'

<script type="text/vbscript">
      sub Sub_Value()
          session("ic_sub_code") = document.getElementsById('cboSubs').Value
          Response.Write "Sub Code: " & session("ic_Sub_Code")
          if mSubValue = "0" then
              Sub.Disabled = True
          else
              Sub.Disabled = False
          end if
      end sub
    </script>





<td><select name="cboSubs" id="cboSubs"  size="1">
                <option value="0">Select a Substitute...</option>
0
 
ggreweAuthor Commented:
Thanks cyberwebservice, I have tried that as well.  It just seems like the onchange event does not fire.  I have tried adding onclick to the submit button, as well as onsubmit to the form.  Nothing seems to make a difference.
0
 
ggreweAuthor Commented:
Well, I found the problem.  In the function "Sub_Value", the session variables were not being set.  The function was actually being called and running.  I was able to narrow down the problem by removing all the code that was related to assigning a variable a value.  So I changed the code to redirect to the page I wanted, passing the value of the combo box.  I was then able to retrieve the value of the combo box, run the query I needed and continue the process.

Thanks for everyones help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.