ASP - option value selected without a ton of code

Asked By R Star on 20-Jul-14 10:43 AM
does anyone know a short way to flag an option value as selected when there are multiple option values...Especially in dates without a lot of if statements...
Basically, I am trying to put the option as selected when returning a date value from a recordset...
Here's an example for day, obviously this would go on for 31 ifs.

 
            <%
              if rsday("rate_dd") = "1" then
            %>
            <option value='01' selected >1</option>
            <option value='02'>2</option>
            <option value='03'>3</option>
            <option value='04'>4</option>
            <option value='05'>5</option>
            <option value='06'>6</option>
            <option value='07'>7</option>
            <option value='08'>8</option>
            <option value='09'>9</option>
            <option value='10'>10</option>
            <option value='11'>11</option>
            <option value='12'>12</option>
            <option value='13'>13</option>
            <option value='14'>14</option>
            <option value='15'>15</option>
            <option value='16'>16</option>
            <option value='17'>17</option>
            <option value='18'>18</option>
            <option value='19'>19</option>
            <option value='20'>20</option>
            <option value='21'>21</option>
            <option value='22'>22</option>
            <option value='23'>23</option>
            <option value='24'>24</option>
            <option value='25'>25</option>
            <option value='26'>26</option>
            <option value='27'>27</option>
            <option value='28'>28</option>
            <option value='29'>29</option>
            <option value='30'>30</option>
            <option value='31'>31</option>
            <%
             elseif rsday("rate_dd") = 2 then
            %>
            <option value='01' selected >1</option>
            <option value='02'>2</option>
            <option value='03'>3</option>
            <option value='04'>4</option>
            <option value='05'>5</option>
            <option value='06'>6</option>
            <option value='07'>7</option>
            <option value='08'>8</option>
            <option value='09'>9</option>
            <option value='10'>10</option>
            <option value='11'>11</option>
            <option value='12'>12</option>
            <option value='13'>13</option>
            <option value='14'>14</option>
            <option value='15'>15</option>
            <option value='16'>16</option>
            <option value='17'>17</option>
            <option value='18'>18</option>
            <option value='19'>19</option>
            <option value='20'>20</option>
            <option value='21'>21</option>
            <option value='22'>22</option>
            <option value='23'>23</option>
            <option value='24'>24</option>
            <option value='25'>25</option>
            <option value='26'>26</option>
            <option value='27'>27</option>
            <option value='28'>28</option>
            <option value='29'>29</option>
            <option value='30'>30</option>
            <option value='31'>31</option>
            <%
             end if 
            %>

uhhhh... - Asked By Robbe Morris on 18-Sep-01 07:22 PM

Why not just write your list while you iterate through 
  the recordset.  If the rsday("rate_dd") is selected,
  then .write your "selected" value.

hmmmm..... - Asked By R Star on 18-Sep-01 08:10 PM

The problem exists in the fact that the other 30 days don't have a value in the recordset and the option to select the others is necessary.  ie if the recordset has the day of 08 then I need to have 01 - 07 and 09 - 31. i am definitely new to programming.  I think something like this may be my answer:  
dim dd(1,30)
for i = 0 to 30
   if i = rsday("rate_dd") then
       dd(1,i) = "selected"
   end if
dd(0,i) = i + 1
response.write "<option value=" & dd(0,i) & dd(1,i) & ">" & dd(0,i) & "</option>"
next 

For some reason this is being a pain. Any suggestions... Sorry the last was rushed.

Looks like your on the right track... - Asked By Robbe Morris on 18-Sep-01 08:59 PM

.
I typically just use client code - Asked By Desert Ghost on 20-Sep-01 12:28 PM
Like you, I hate doing all those loops... so on your window_onload event, I just do:

document.formname.selectboxname.selectedvalue = <%=yourThing%>;


It's been awhile since I've used this, so I can't remember if selectedvalue is the right one.  Ya can do some digging to find it.
well hell thats easy enough - Asked By R Star on 20-Jul-14 10:44 AM
Pretty simple answer.  This helps for a shit ton of usability issues I've been dealing with,
Danke.