Drop Down Default Selected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JayB

    Drop Down Default Selected

    I am creating an online survey for one of our grants and one of the items to
    be answered is county (U.S.). The county is to be in a drop-down menu to
    prevent typos and counties from other states by mistake. I'm doing
    server-side validation (many of our users have disabled JavaScript) and need
    to retain the user's selection if they need to revisit the page to make
    corrections.

    In the past I'd declare variables for each choice in the drop-down menu
    (usually they are no more than five or six choices for what I've done) and
    use a select case to set one of the variables to ' SELECTED'. However, in
    the county list there are 86 choices.

    What would be the most efficient way to retain the users selection if they
    need to go back to fix errors? I also am looking for a similar solution for
    many checkboxes.

    Thanks,

    --
    JayB


  • Ray Costanzo [MVP]

    #2
    Re: Drop Down Default Selected

    What does the code look like that you're using the display the dropdown box?
    Do these values from a recordset, an array, just hard-coded ino the HTML,
    something else?

    Ray at work

    "JayB" <jerry280@yahoo .com> wrote in message
    news:7Kx9d.8785 $bw3.1822@news0 2.roc.ny...[color=blue]
    >I am creating an online survey for one of our grants and one of the items
    >to be answered is county (U.S.). The county is to be in a drop-down menu to
    >prevent typos and counties from other states by mistake. I'm doing
    >server-side validation (many of our users have disabled JavaScript) and
    >need to retain the user's selection if they need to revisit the page to
    >make corrections.
    >
    > In the past I'd declare variables for each choice in the drop-down menu
    > (usually they are no more than five or six choices for what I've done) and
    > use a select case to set one of the variables to ' SELECTED'. However, in
    > the county list there are 86 choices.
    >
    > What would be the most efficient way to retain the users selection if they
    > need to go back to fix errors? I also am looking for a similar solution
    > for many checkboxes.
    >
    > Thanks,
    >
    > --
    > JayB
    >[/color]


    Comment

    • JayB

      #3
      Re: Drop Down Default Selected

      Hard-coded HTML.

      --
      JayB


      "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
      message news:%23JbGWkUr EHA.2644@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      > What does the code look like that you're using the display the dropdown
      > box? Do these values from a recordset, an array, just hard-coded ino the
      > HTML, something else?
      >
      > Ray at work
      >
      > "JayB" <jerry280@yahoo .com> wrote in message
      > news:7Kx9d.8785 $bw3.1822@news0 2.roc.ny...[color=green]
      >>I am creating an online survey for one of our grants and one of the items
      >>to be answered is county (U.S.). The county is to be in a drop-down menu
      >>to prevent typos and counties from other states by mistake. I'm doing
      >>server-side validation (many of our users have disabled JavaScript) and
      >>need to retain the user's selection if they need to revisit the page to
      >>make corrections.
      >>
      >> In the past I'd declare variables for each choice in the drop-down menu
      >> (usually they are no more than five or six choices for what I've done)
      >> and use a select case to set one of the variables to ' SELECTED'.
      >> However, in the county list there are 86 choices.
      >>
      >> What would be the most efficient way to retain the users selection if
      >> they need to go back to fix errors? I also am looking for a similar
      >> solution for many checkboxes.
      >>
      >> Thanks,
      >>
      >> --
      >> JayB
      >>[/color]
      >
      >[/color]


      Comment

      • Ray Costanzo [MVP]

        #4
        Re: Drop Down Default Selected

        Well that kinda sucks... What you can do is:
        <%
        Dim s
        s = Request.Form("d ropdownName")
        %>
        <select name="dropdownN ame">
        <option value="1"<% If s = "1" Then Response.Write " selected"%>>Opt ion
        1</option>
        <option value="2"<% If s = "2" Then Response.Write " selected"%>>Opt ion
        2</option>
        ...
        </select>

        Ray at work

        "JayB" <jerry280@yahoo .com> wrote in message
        news:cly9d.8794 $Jt3.8681@news0 2.roc.ny...[color=blue]
        > Hard-coded HTML.
        >
        > --
        > JayB
        >
        >
        > "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
        > message news:%23JbGWkUr EHA.2644@TK2MSF TNGP15.phx.gbl. ..[color=green]
        >> What does the code look like that you're using the display the dropdown
        >> box? Do these values from a recordset, an array, just hard-coded ino the
        >> HTML, something else?
        >>
        >> Ray at work
        >>
        >> "JayB" <jerry280@yahoo .com> wrote in message
        >> news:7Kx9d.8785 $bw3.1822@news0 2.roc.ny...[color=darkred]
        >>>I am creating an online survey for one of our grants and one of the items
        >>>to be answered is county (U.S.). The county is to be in a drop-down menu
        >>>to prevent typos and counties from other states by mistake. I'm doing
        >>>server-s[/color][/color][/color]


        Comment

        • Joker

          #5
          Re: Drop Down Default Selected

          I always had an extra option at the top of the list that was always
          selected that would contain the name of whatever was selected in the
          list. This did make the state listed twice, but it was easier then
          getting it listed only once.

          JayB wrote:
          [color=blue]
          > I am creating an online survey for one of our grants and one of the items to
          > be answered is county (U.S.). The county is to be in a drop-down menu to
          > prevent typos and counties from other states by mistake. I'm doing
          > server-side validation (many of our users have disabled JavaScript) and need
          > to retain the user's selection if they need to revisit the page to make
          > corrections.
          >
          > In the past I'd declare variables for each choice in the drop-down menu
          > (usually they are no more than five or six choices for what I've done) and
          > use a select case to set one of the variables to ' SELECTED'. However, in
          > the county list there are 86 choices.
          >
          > What would be the most efficient way to retain the users selection if they
          > need to go back to fix errors? I also am looking for a similar solution for
          > many checkboxes.
          >
          > Thanks,
          >[/color]

          --
          Please do not contact me directly or ask me to contact you directly for
          assistance.

          If your question is worth asking, it's worth posting.

          If it’s not worth posting you should have done a search on
          http://www.google.com/ http://www.google.com/grphp?hl=en&tab=wg&q= or
          http://news.google.com/froogle?hl=en&tab=nf&ned=us&q= before wasting our
          time.

          Comment

          • JayB

            #6
            Re: Drop Down Default Selected

            Ray, thanks for the suggestion.

            I put the counties in their own table and read them from the asp page. I use
            an if statement to determine if it's selected or not. Thanks again for your
            suggestion, it got me thinking on the right track.

            --
            JayB

            "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
            message news:O$LUyvUrEH A.2244@TK2MSFTN GP15.phx.gbl...[color=blue]
            > Well that kinda sucks... What you can do is:
            > <%
            > Dim s
            > s = Request.Form("d ropdownName")
            > %>
            > <select name="dropdownN ame">
            > <option value="1"<% If s = "1" Then Response.Write " selected"%>>Opt ion
            > 1</option>
            > <option value="2"<% If s = "2" Then Response.Write " selected"%>>Opt ion
            > 2</option>
            > ...
            > </select>
            >
            > Ray at work
            >
            > "JayB" <jerry280@yahoo .com> wrote in message
            > news:cly9d.8794 $Jt3.8681@news0 2.roc.ny...[color=green]
            >> Hard-coded HTML.
            >>
            >> --
            >> JayB
            >>
            >>
            >> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
            >> message news:%23JbGWkUr EHA.2644@TK2MSF TNGP15.phx.gbl. ..[color=darkred]
            >>> What does the code look like that you're using the display the dropdown
            >>> box? Do these values from a recordset, an array, just hard-coded ino the
            >>> HTML, something else?
            >>>
            >>> Ray at work
            >>>
            >>> "JayB" <jerry280@yahoo .com> wrote in message
            >>> news:7Kx9d.8785 $bw3.1822@news0 2.roc.ny...
            >>>>I am creating an online survey for one of our grants and one of the
            >>>>items to be answered is county (U.S.). The county is to be in a
            >>>>drop-down menu to prevent typos and counties from other states by
            >>>>mistake. I'm doing server-s[/color][/color]
            >
            >[/color]


            Comment

            • dlbjr

              #7
              Re: Drop Down Default Selected

              Most Effiecient:

              Since the items in the select box will not change (much), I would list the items in the global.asa
              with an Application variable like so:

              Application("ST ATES") = "AL,NY,TX,OK,GA "

              Use the following code in an ASP Page.

              Sub BuildStateDropD own(strDefault)
              With Response
              .Write "<select id='STATE' name='STATE'>"
              arData = Split(Applicati on("STATES"),", ")
              For i = 0 To UBound(arData)
              strItem = arData(i)
              .Write "<option value='"
              .Write strItem
              .Write "'"
              If strDefault = strItem Then
              .Write " SELECTED"
              End If
              .Write ">"
              .Write strItem
              .Write "</option>"
              Next
              .Write </select>"
              End With
              End Sub

              'dlbjr
              'Pleading sagacious indoctrination!


              Comment

              • Dave Anderson

                #8
                Re: Drop Down Default Selected

                dlbjr wrote:[color=blue]
                > Most Effiecient:[/color]

                Doubtful, since multiple usage means multiple Splits. Not to mention the
                syntax error it will generate on the following line:
                [color=blue]
                > .Write </select>"[/color]



                --
                Dave Anderson

                Unsolicited commercial email will be read at a cost of $500 per message. Use
                of this email address implies consent to these terms. Please do not contact
                me directly or ask me to contact you directly for assistance. If your
                question is worth asking, it's worth posting.


                Comment

                • Dave Anderson

                  #9
                  Re: Drop Down Default Selected

                  JayB wrote:[color=blue]
                  > What would be the most efficient way to retain the users selection if
                  > they need to go back to fix errors? I also am looking for a similar
                  > solution for many checkboxes.[/color]

                  JScript makes it so easy. Stick this in one of your global includes:
                  Array.prototype .toOptions = function(val) {
                  for (var i=0,a=[]; i<this.length; i++) a.push(
                  "<OPTION VALUE=\"" + this[i] +
                  (this[i]==val ? "\" SELECTED>" : "\">") +
                  this[i] + "</OPTION>"
                  )
                  return a.join("")
                  }

                  Now ANY array can spit out a set of options. For example, an array of state
                  codes:

                  Define your array inline...
                  var States = new Array("AK","AL" ,"AR",...,"W Y")

                  ....or from a data source:
                  for (var States=[]; !RS.EOF; RS.MoveNext())
                  States.push(RS. Fields("State") .Value)

                  Call the method to generate the set of options:
                  var StateList = States.toOption s(Request.Form( "State").It em)

                  Put it inline in your template:
                  <SELECT NAME="State"><% =StateList%></SELECT>



                  --
                  Dave Anderson

                  Unsolicited commercial email will be read at a cost of $500 per message. Use
                  of this email address implies consent to these terms. Please do not contact
                  me directly or ask me to contact you directly for assistance. If your
                  question is worth asking, it's worth posting.


                  Comment

                  Working...