473,699 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select (dropdown) list and set value based on table column

I have an old application ( pre-VB5) that I need to add a select/option list
to. This is an edit program so the values for the form will be retrieved
from a database. How do I set the value of the dropdown with the value from
the database. The value in the database is either new, trial, maint.,
employee, beta, or null. I need to set the dropdrown to one of these values.

An example of the select;
<td>
<select name="ordReason ">
<option></option>
<option value="New">New </option>
<option value="Maint."> Maint.</option>
<option value="Trial">T rial</option>
<option value="Employee ">Employee</option>
<option value="Beta">Be ta</option>
</select>
</td>
Jan 23 '07 #1
5 13868
mcauliffe wrote:
I have an old application ( pre-VB5) that I need to add a
select/option list to. This is an edit program so the values for the
form will be retrieved from a database. How do I set the value of
the dropdown with the value from the database. The value in the
database is either new, trial, maint., employee, beta, or null. I
need to set the dropdrown to one of these values.

An example of the select;
<td>
<select name="ordReason ">
<option></option>
<option value="New">New </option>
<option value="Maint."> Maint.</option>
<option value="Trial">T rial</option>
<option value="Employee ">Employee</option>
<option value="Beta">Be ta</option>
</select>
</td>
When adding the options, add the word " checked" to the option tag of
the one you want selected.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 23 '07 #2
mcauliffe wrote:
Thank you for the reply.

I don't know which one will bew selected until I retrieved a record
from the database. The user is editing a existing record and may
changed the value of the dropdown. I must first indicate the value
is the database.

An example: the database for the column is equal to "Employee" How
do I indicate when I display the ASP page on the form that the
existing value of ordReason is Employee?
Concatenate "checked" into the option value text when building the
option string.

You are building these options by looping through some records in a
recordset, correct? When you get to the one that contains "Employee",
concatenate "selected" (not "checked" - oops) into the option tag.
Obviously, this means you need to know/retrieve the selected value
before building the option list.

Here's a simple example using an array instead of a recordset (since i
don't have access to your database, of course):

<%
dim options, ar, selectedvalue, val
selectedvalue=R equest.Form("se l")
ar=array("New", "Maint.","Trial ","Employee","B eta")
for each val in ar
options=options & "<option value=""" & val & """"
if val=selectedval ue then options=options & " selected"
options=options & ">" & val
next
%>
<html><body><fo rm method="post">
<select name="sel">
<%=options%>
</select><br>
<input type="submit">
</form></body></html>

next
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 23 '07 #3
I can recommend my procedure for building select box.
parameter "arr" is 2 dimensional array taken from query and based on 2
fields; id and name, using method getrows
parameter "id" is value that should be checked

Sub FillSelectBox(a rr, selectname, action, size, id)
Dim Sel
Response.Write "<select name=" & selectname & " onchange=" & action
& " style='width:" & size & "px;'>"
For i=0 to Ubound(arr,2)
If cint(id)=cint(a rr(0,i)) Then
Sel=" selected "
Else
Sel=" "
End If
Response.Write "<option" & Sel & " value=" & arr(0,i) & ">"
& arr(1,i) & "</option>"
Next
Response.write "</select>"
End Sub
example of calling
<%
sql="Select CustomerId, CustomerName from Customers order by CustomerName"
call getfromdatabase (sql, rs) ' your own function to get query
If Not rs.eof Then
array=rs.GetRow s
End If
call FillSelectBox(a rray, "Types", "changesomethin g(" & rs("CustomerId" ) &
")", 20, "Smith")
%>
Michael
Jan 24 '07 #4
=?Utf-8?B?bWNhdWxpZmZ l?= wrote on 24 jan 2007 in
microsoft.publi c.inetserver.as p.general:
As a newbie, needed something that I would undetstand. Your response
help me. I did a Select Case and resolved.

This is a snipet of the code
Select Case rsorder_header. fields.getValue ("order_reason" )
Case ""
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option Selected></option>" & _
"<option value='New'>New </option>" & _
"<option value='Maint.'> Maint.</option>" & _
"<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"
Case "New"
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option></option>" & _
"<option value='New' Selected>New</option>" & _
"<option value='Maint.'> Maint.</option>" & _
"<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"
Case "Maint."
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option></option>" & _
"<option value='New'>New </option>" & _
"<option value='Maint.' Selected>Maint. </option>"
& _ "<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"
Why not use ASP-VBS to optimize your code:
<%
Function writeOption(t)
If rsn = t Then s = "Selected" Else s = ""
Response.Write "<option value='"&t&"'"& s&">"&t&"</option>" & VbCrLf
End Function

rsn = rsorder_header. fields.getValue ("order_reason" )
%>
<td width=100>
<select name='ordReason '>
<%
writeOption("")
writeOption("Ne w")
writeOption("Ma int.")
writeOption("Tr ial")
writeOption("Em ployee")
writeOption("Be ta")
%>
</select>
</td>

Not tested btw.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 24 '07 #5
Thanks all. Commenting out the section that produced the headers
worked.

On Jan 24, 10:22 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net >
wrote:
=?Utf-8?B?bWNhdWxpZmZ l?= wrote on 24 jan 2007 in
microsoft.publi c.inetserver.as p.general:


As a newbie, needed something that I would undetstand. Your response
help me. I did a Select Case and resolved.
This is a snipet of the code
Select Case rsorder_header. fields.getValue ("order_reason" )
Case ""
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option Selected></option>" & _
"<option value='New'>New </option>" & _
"<option value='Maint.'> Maint.</option>" & _
"<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"
Case "New"
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option></option>" & _
"<option value='New' Selected>New</option>" & _
"<option value='Maint.'> Maint.</option>" & _
"<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"
Case "Maint."
Response.Write "<td width=100>" & _
"<select name='ordReason '>" & _
"<option></option>" & _
"<option value='New'>New </option>" & _
"<option value='Maint.' Selected>Maint. </option>"
& _ "<option value='Trial'>T rial</option>" & _
"<option Value='Employee '>Employee</option>" & _
"<option value='Beta'>Be ta</option></select></td>"Why not use ASP-VBS to optimize your code:

<%
Function writeOption(t)
If rsn = t Then s = "Selected" Else s = ""
Response.Write "<option value='"&t&"'"& s&">"&t&"</option>" & VbCrLf
End Function

rsn = rsorder_header. fields.getValue ("order_reason" )
%>
<td width=100>
<select name='ordReason '>
<%
writeOption("")
writeOption("Ne w")
writeOption("Ma int.")
writeOption("Tr ial")
writeOption("Em ployee")
writeOption("Be ta")
%>
</select>
</td>

Not tested btw.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)- Hide quoted text -- Show quoted text -
Jan 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2591
by: Toonman | last post by:
I have a webpage with a <form> consisting of a large table grid of dropdown lists used to make changes in a database. Some of these dropdown lists have the same value. I'm trying to make it so that when a user mouses over one of the dropdown lists, that dropdown list, and all other dropdown lists having that same value are highlighted with a yellow background color. Then on a mouseout the yellow highlights go away. The goal is to it...
6
3468
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I want to be able to select an item on the dropdown list based on the value of the javascript variable. Let's say this is my list and my variable: <select id='popup'>
3
583
by: Alex | last post by:
Hi, I need to form a query where i can add some columns based on the result. Table A ColA, ColB ---------- 1 A 2 B
3
2884
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source first, then the Table list box populates only tables from that source. Once a table is chosen, only the columns for that table appear in the Column list box. In the date box, the only dates that appear are those that are stored against the...
2
2408
by: DotNetJunkies User | last post by:
hi,, im trying to work out what code is needed for the below problem about databinding a dropdown list and having actual datalist items as value "0" ie 'please select' can anyone tell me how to do this in relation to the below code,, thanks paul.
6
13003
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this is not an ASP.NET related question, but I know this group is knowledgeable and quick with responses. Thanks
2
3327
by: rn5a | last post by:
During registration, users have to provide their date of birth. For the date & month part, there are 2 dropdown lists & for the year, there's a textbox. These 3 fields are finally merged together to populate a MS-Access database table in a column named DOB whose data type is Date/Time. There's another page named, say, MyPage.asp, in the same application where users have to again enter their date of birth. Like the registration page,...
1
24326
by: RichardR | last post by:
I have a webpage which has a table that contains a column with several drop down boxes (<SELECT>). The contents of the drop down boxes are dynamically populated so I have no idea what the actually width will be necessary. How do I tell the dropdown (<SELECT>) and/or column (<TD>) to automatically size itself to the greater of widest item in the dropdown, and then get the smaller dropdowns to fill the width of the column? If I specify in...
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.