-1

I have two dropdown lists on a classic asp page:

<select id="ddlState" name="ddlState" runat="server">
<option value="KY">Kentucky</option>
<option value="IN">Indiana</option>
<option value="OH">Ohio</option>
<option value="TN">Tennessee</option>
</select>

<select name="ddlCounty">
<% if ddlState = "KY" then %>
<option>Adair</option>
<option>Allen</option>
<option>Anderson</option>
<% end if %>

<option>IN County</option>
<option>OH County</option>
<option>TN County</option>
</select>

I am attempting to figure out what is wrong with the following:

<%
    response.write "Test"
    response.write "<br />"
    response.write ddlState
    response.write "<br />"
    response.write "Test2"

%>

I've tried these variations, as well:

response.write StateDropdown.value

and

Dim ddlState 
set ddlState = document.getElementById("ddlState")
response.write ddlState.value

Anyone know what I am doing wrong, here? I wish I didn't have to use classic asp, but it is what it is and I am not super familiar with it.

user692942
  • 16,398
  • 7
  • 76
  • 175
Peter F
  • 435
  • 1
  • 8
  • 17
  • 1
    Where is `ddlState` being set? – user692942 Jan 20 '22 at 18:19
  • It is both the name and the id of one of the select elements. I tried setting it as an object with the document.getElementById then calling that, but I get the following error: Microsoft VBScript runtime error '800a01a8' Object required: '' /RateCalculator/test.asp, line 226 – Peter F Jan 20 '22 at 18:21
  • 1
    It also entirely depends on the approach. Are you submitting a form to update the dropdown or are you trying to update the dropdown client-side which wouldn’t require Classic ASP at all? – user692942 Jan 20 '22 at 18:21
  • I would like to update client side. – Peter F Jan 20 '22 at 18:22
  • 1
    If you are trying to retrieve the value of a submitted value in a form you use `ddlState = Request.QueryString("ddlState")` if it’s a `GET` submission or `ddlState = Request.Form("ddlState")` if its a `POST` submission. – user692942 Jan 20 '22 at 18:24
  • I didn't intend to submit the form until these options are chosen by the user, but I was hoping I could make the county dropdownlist depend on the state dropdown. Is that not possible? – Peter F Jan 20 '22 at 18:25
  • 1
    If client-side make sure you are writing a client-side script in the HTML body and then use `document.getElementById("ddlState")`. – user692942 Jan 20 '22 at 18:25
  • 1
    It is entirely possible, but not inside the server-side code (`<% %>`), for example `Response.Write` is a server-side call. If you want to do this client-side Classic ASP is irrelevant to the question. – user692942 Jan 20 '22 at 18:27
  • 1
    Does this answer your question? [Drop-down box dependent on the option selected in another drop-down box](https://stackoverflow.com/q/19728666/692942) – user692942 Jan 20 '22 at 18:29

1 Answers1

0

I was able to accomplish my objectives by using multiple dropdown lists and showing/hiding them.

$(document).on('ready', function () {


$("#ddlCountyKY").show()
$("#ddlCountyOH").hide()
$("#ddlCountyIN").hide()
$("#ddlCountyTN").hide()

$("#ddlState").on('change', function () {
    var el = $(this);
    if (el.val() === "KY") {
        $("#ddlCountyKY").show()
        $("#ddlCountyOH").hide()
        $("#ddlCountyIN").hide()
        $("#ddlCountyTN").hide()
    } else if (el.val() === "OH") {
        $("#ddlCountyKY").hide()
        $("#ddlCountyOH").show()
        $("#ddlCountyIN").hide()
        $("#ddlCountyTN").hide()
    } else if (el.val() === "IN") {
        $("#ddlCountyKY").hide()
        $("#ddlCountyOH").hide()
        $("#ddlCountyIN").show()
        $("#ddlCountyTN").hide()
    } else if (el.val() === "TN") {
        $("#ddlCountyKY").hide()
        $("#ddlCountyOH").hide()
        $("#ddlCountyIN").hide()
        $("#ddlCountyTN").show()
    }
});

});

Peter F
  • 435
  • 1
  • 8
  • 17