[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting session varible to value of dropdown combo

Posted on 2007-10-10
7
Medium Priority
?
551 Views
Last Modified: 2008-01-09
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]
0
Comment
Question by:ggrewe
  • 4
  • 2
7 Comments
 
LVL 20

Expert Comment

by:Gawai
ID: 20050956
<select name="cboSubs" onChange="document.Substitute.cboSubs.options[selectedIndex].value=<%=session("ic_sub_code")%>>
0
 

Author Comment

by:ggrewe
ID: 20051633
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
 

Author Comment

by:ggrewe
ID: 20053291
This does not seem to work either.  

<select name="cboSubs" onChange=<%session("ic_sub_code")%> = document.Substitute.cboSubs.options[selectedIndex].value">
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 20054431
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
 

Author Comment

by:ggrewe
ID: 20055689
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
 
LVL 20

Accepted Solution

by:
Gawai earned 150 total points
ID: 20060216
better you use cookies instead of session
0
 

Author Comment

by:ggrewe
ID: 20070854
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question