Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Drop Down Default Selected (http://www.velocityreviews.com/forums/t796657-drop-down-default-selected.html)

JayB 10-08-2004 02:45 PM

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] 10-08-2004 03:12 PM

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@news02.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-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
>




JayB 10-08-2004 03:27 PM

Re: Drop Down Default Selected
 
Hard-coded HTML.

--
JayB


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:%23JbGWkUrEHA.2644@TK2MSFTNGP15.phx.gbl...
> 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@news02.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-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] 10-08-2004 03:32 PM

Re: Drop Down Default Selected
 
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" <jerry280@yahoo.com> wrote in message
news:cly9d.8794$Jt3.8681@news02.roc.ny...
> Hard-coded HTML.
>
> --
> JayB
>
>
> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
> message news:%23JbGWkUrEHA.2644@TK2MSFTNGP15.phx.gbl...
>> 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@news02.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




Joker 10-08-2004 04:18 PM

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:

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

JayB 10-08-2004 05:20 PM

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$LUyvUrEHA.2244@TK2MSFTNGP15.phx.gbl...
> 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" <jerry280@yahoo.com> wrote in message
> news:cly9d.8794$Jt3.8681@news02.roc.ny...
>> Hard-coded HTML.
>>
>> --
>> JayB
>>
>>
>> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
>> message news:%23JbGWkUrEHA.2644@TK2MSFTNGP15.phx.gbl...
>>> 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@news02.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

>
>




dlbjr 10-08-2004 08:39 PM

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("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!



Dave Anderson 10-08-2004 09:20 PM

Re: Drop Down Default Selected
 
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.



Dave Anderson 10-08-2004 09:25 PM

Re: Drop Down Default Selected
 
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.




All times are GMT. The time now is 11:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.