422,024 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,024 IT Pros & Developers. It's quick & easy.

case select capture value from which button was clicked

P: 2
I have a form with 6 fields. 3 of fields have their own submit button (using button element). I have a select case conditional to capture what button was used. My "Case"'s do not catch the value. I use a request.form("variable") to catch the value of the button.
line 100 is where I catch the value, line 72 is the first of the 3 buttons. would be easier with javascript and onclick functions, but trying to learn ASP Classic. The purpose of this form is to build a query based on what they enter, so each case statement would assign the correct sql based on what they were using to search.
Expand|Select|Wrap|Line Numbers
  1.  <form method="post" action="test-17.asp" >         
  2.              <fieldset class="centerMe">
  3.                  <span id="HotItems" >
  4.                      Show Only Hot Items?
  5.                      <input type="radio" name="hotItem" value="No"  checked/><label for="No">No</label>
  6.                      <input type="radio" name="hotItem" value="Yes" /><label for="Yes">Yes</label>                     
  7.                  </span>
  8.                  <span class="pipeLine">|</span>
  9.                  <span>
  10.                     <select required id="stateID"  name="selectedState"  style="display:inline;">
  11.                       <option value="" selected ="selected">State Choice...</option>                     
  12.                       <option value="AZ">Arizona</option>                     
  13.                       <option value="CO">Colorado</option>                    
  14.                       <option value="GA">Georgia</option>                    
  15.                       <option value="ID">Idaho</option>
  16.                       <option value="IL">Illinois</option>
  17.                       <option value="IN">Indiana</option>
  18.                       <option value="IA">Iowa</option>
  19.                       <option value="KS">Kansas</option>                      
  20.                       <option value="MN">Minnesota</option>                    
  21.                       <option value="MO">Missouri</option>
  22.                       <option value="MT">Montana</option>
  23.                       <option value="NE">Nebraska</option>
  24.                       <option value="NV">Nevada</option>                    
  25.                       <option value="ND">North Dakota</option>
  26.                       <option value="OH">Ohio</option>                    
  27.                       <option value="SD">South Dakota</option>                     
  28.                       <option value="UT">Utah</option>                     
  29.                       <option value="WA">Washington</option>                     
  30.                       <option value="WI">Wisconsin</option>                      
  31.                     </select>
  32.                 </span>
  33. <%
  34.  
  35.                     dim hotItemYN
  36.                      hotItemYN = request.form("hotItem")
  37.                     dim objRs
  38.                     Set objRs = Server.CreateObject("ADODB.Recordset")
  39.                     dim sicInput
  40.                     sicInput = request.Form("sicInput")        
  41.                     dim sicSQL
  42.                     sicSQL= "Select distinct(SIC), SIC_Description from MatrixTable"
  43.  
  44.                     objRs.Open sicSQL, connectionStringToAccess
  45.  
  46.                     dim covRS        
  47.                     Set covRS = Server.CreateObject("ADODB.Recordset")
  48.                     dim covSQL
  49.                     coverageInput = request.Form("coverageInput")
  50.                     covSQL = "select distinct(Coverages) from MatrixTable"
  51.                     covRS.Open covSQL, connectionStringToAccess
  52.  
  53.  
  54.                     ''''''''create the drop down for Coverages '''''''
  55.                     Response.Write "<select name='coverageInput' >"
  56.                     response.write " <option value='' selected> Coverage Choice... </option>"
  57.  
  58.                         Do While Not covRS.EOF 
  59.                         'Response.Write "<TD>" & objRs("SIC") & "</TD>"
  60.                             Response.Write "<option value='" & covRS("Coverages") & "'>'" & covRS("Coverages") & "'</option>"
  61.                         covRS.MoveNext
  62.                         Loop
  63.                     Response.Write "</select>"
  64.  
  65. %>
  66.                 <!-- <label for="mySearchBox">Search by SIC:</label> -->
  67.  
  68.                 <!-- <input class="" type="submit"  /> -->
  69.  
  70.  
  71.             </fieldset>
  72.             <fieldset class="centerMe">
  73.                    <!-- <label for="mySearchBox">Search with multiple Keywords:</label> -->
  74.                    <input id="mySearchBox-keyword" name="textInput" class="formButtons" type="text">
  75.                    <button class="input" type="submit" name="mySubmit" value="keywordSubmit">Search by Keyword</button>
  76.                </fieldset>
  77.             <fieldset class="centerMe">
  78.                    <!-- <label for="mySearchBox">Search with multiple Keywords:</label> -->
  79.                    <input id="mySearchBox-sicDescription" name="textInput" class="formButtons" type="text">
  80.                    <button class="input" type="submit" name="mySubmit" value="SicSubmit">Search by SIC Description</button>
  81.                </fieldset>
  82.             <fieldset class="centerMe">
  83.                    <!-- <label for="mySearchBox">Search with multiple Keywords:</label> -->
  84.                    <input id="mySearchBox-SIC" name="textInput" class="formButtons" type="text">
  85.                    <button class="input" type="submit" name="mySubmit" value="sicDescrSubmit">Search by SIC</button>
  86.                </fieldset>
  87.  
  88.         </form> 
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.                 <% 
  97.                 'Which submit button was used? asign the proper SQL to the button'
  98.                 dim mySubmit 
  99.                 Dim sicDescrSubmit, myQuery, keywordSubmit, SicSubmit
  100.                 mySubmit = request.form("mySubmit")
  101.                 if mySubmit <> "" then
  102.                     Select Case mySubmit
  103.                         Case sicDescrSubmit
  104.                             myQuery="sicDescrSubmit"
  105.                         Case SicSubmit 
  106.                             myQuery="SicSubmit"
  107.                         Case keywordSubmit
  108.                             myQuery="keywordSubmit"
  109.                             response.write("keywordSubmit")
  110.                         Case Else
  111.                             response.write("Please Submit one of the buttons")
  112.                     End Select
  113.                 else myQuery = ""
  114.                 End if
  115.                 response.write myQuery
  116.  
Sep 11 '17 #1

✓ answered by jhardman

is this going to the case else every time?

syntax should be:

Expand|Select|Wrap|Line Numbers
  1.    Case "sicDescrSubmit"
  2.                             myQuery="sicDescrSubmit"
  3.                         Case "SicSubmit"
  4.                             myQuery="SicSubmit"
value should be in quotes. but I'm not sure that is the only issue.

Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,401
is this going to the case else every time?

syntax should be:

Expand|Select|Wrap|Line Numbers
  1.    Case "sicDescrSubmit"
  2.                             myQuery="sicDescrSubmit"
  3.                         Case "SicSubmit"
  4.                             myQuery="SicSubmit"
value should be in quotes. but I'm not sure that is the only issue.
Nov 28 '17 #2

P: 2
Thank you Jhardman. I did give up and put them all in one form instead, but now I see what I did wrong. Thanks
Nov 30 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.