Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Drop Down Default Selected

Reply
Thread Tools

Drop Down Default Selected

 
 
JayB
Guest
Posts: n/a
 
      10-08-2004
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


 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-08-2004
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" <> wrote in message
news:7Kx9d.8785$...
>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
>



 
Reply With Quote
 
 
 
 
JayB
Guest
Posts: n/a
 
      10-08-2004
Hard-coded HTML.

--
JayB


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:%...
> 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" <> wrote in message
> news:7Kx9d.8785$...
>>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
>>

>
>



 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-08-2004
Well that kinda sucks... What you can do is:
<%
Dim s
s = Request.Form("dropdownName")
%>
<select name="dropdownName">
<option value="1"<% If s = "1" Then Response.Write " selected"%>>Option
1</option>
<option value="2"<% If s = "2" Then Response.Write " selected"%>>Option
2</option>
...
</select>

Ray at work

"JayB" <> wrote in message
news:cly9d.8794$...
> Hard-coded HTML.
>
> --
> JayB
>
>
> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
> message news:%...
>> 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" <> wrote in message
>> news:7Kx9d.8785$...
>>>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



 
Reply With Quote
 
Joker
Guest
Posts: n/a
 
      10-08-2004
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:

> 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,
>


--
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.
 
Reply With Quote
 
JayB
Guest
Posts: n/a
 
      10-08-2004
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$...
> Well that kinda sucks... What you can do is:
> <%
> Dim s
> s = Request.Form("dropdownName")
> %>
> <select name="dropdownName">
> <option value="1"<% If s = "1" Then Response.Write " selected"%>>Option
> 1</option>
> <option value="2"<% If s = "2" Then Response.Write " selected"%>>Option
> 2</option>
> ...
> </select>
>
> Ray at work
>
> "JayB" <> wrote in message
> news:cly9d.8794$...
>> Hard-coded HTML.
>>
>> --
>> JayB
>>
>>
>> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
>> message news:%...
>>> 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" <> wrote in message
>>> news:7Kx9d.8785$...
>>>>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

>
>



 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      10-08-2004
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("STATES") = "AL,NY,TX,OK,GA"

Use the following code in an ASP Page.

Sub BuildStateDropDown(strDefault)
With Response
.Write "<select id='STATE' name='STATE'>"
arData = Split(Application("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!


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      10-08-2004
dlbjr wrote:
> Most Effiecient:


Doubtful, since multiple usage means multiple Splits. Not to mention the
syntax error it will generate on the following line:

> .Write </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.


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      10-08-2004
JayB wrote:
> 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.


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",...,"WY")

....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.toOptions(Request.Form("State").Item)

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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1st Drop-down selection determins selected value in all drop-downs In ASP.Net Wizard jaysch ASP .Net 0 04-30-2011 02:19 PM
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
Enable second drop down after first drop down is selected teser3@hotmail.com Javascript 0 01-28-2009 12:59 AM
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
New to .NET, can I have one drop down box control the data of another drop down box using a database? SirPoonga ASP .Net 2 01-07-2005 10:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57