473,888 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating a multiple select box from a database

37 New Member
Hi

I have a HTML form with a multiple select box. The multiple select box is populated from a database. A user can select multiple options form this select box and the infomrtaion is then stored in a database.

The user then has the option to edit their saved record. How do i populate this multiple select box from a database with the users selected/saved options highlighted?

I can manage to get it to work if the user simply selected one option but not for multiple options. how do i iterate the record set with the saved options whilst at the same time comparing with a record set that populates the multiple select box? Sample code would be help full.
Feb 15 '07 #1
7 5310
shweta123
692 Recognized Expert Contributor
Hi,

set rs=con.executes (sql)
<OPTION selected></OPTION>
<SELECT multiple>
<%while not rs.EOF%>
<%' Here you can put the condition to decide wheather to display it selected or not%>
<%'If yes%>
<OPTION selected><%=rs. Fields(0)%></OPTION>
<<%'else%>
<OPTION><%=rs.F ields(0)%></OPTION>

<%rs.MoveNext
Wend%>
</SELECT>
Feb 16 '07 #2
ozzii
37 New Member
Hi,

set rs=con.executes (sql)
<OPTION selected></OPTION>
<SELECT multiple>
<%while not rs.EOF%>
<%' Here you can put the condition to decide wheather to display it selected or not%>
<%'If yes%>
<OPTION selected><%=rs. Fields(0)%></OPTION>
<<%'else%>
<OPTION><%=rs.F ields(0)%></OPTION>

<%rs.MoveNext
Wend%>
</SELECT>
Hi,

I dont think the above code will work becuase its not comparing with a second record set with the saved options.

To clarify my point - i have one record set which is used to populate the multiple select box. A second record set has the saved options. The first recordset would need to compare each option value with each saved option value to decide if it should be selected or not.
Feb 16 '07 #3
jhardman
3,406 Recognized Expert Specialist
To clarify my point - i have one record set which is used to populate the multiple select box. A second record set has the saved options. The first recordset would need to compare each option value with each saved option value to decide if it should be selected or not.
In what format is the data in the two rs's? If I was starting this project I think I would first open the rs with the saved selected options and use that to populate an array. Then I would open the rs with all of the options. As I'm constructing the select box, I would check each value against the array to decide if it is selected or not. If the two lists should always be in the same order, you won't even have to scroll through the array more than once.
Feb 17 '07 #4
shweta123
692 Recognized Expert Contributor
Hi,

Does both the recordsets contain same no of records?
I am assuming that 2 recordsets are in the same order.
You can write it this way

set rs=con.executes (sql) 'rs contains data to fill the listbox
set rs1=con.execute s(sql) 'rs1 contains data with saved options

<OPTION selected></OPTION>
<SELECT multiple>
<%while not rs.EOF%>
<%while not rs1.EOF%>
<% If rs1.fields("Opt ions")="Yes"%>
<OPTION selected><%=rs. Fields(0)%></OPTION>
<%else%>
<OPTION><%=rs.F ields(0)%></OPTION>

<%rs.MoveNext
%rs1.Movenext
Wend%>
</SELECT>
Feb 19 '07 #5
ozzii
37 New Member
Hi,

Does both the recordsets contain same no of records?
I am assuming that 2 recordsets are in the same order.
You can write it this way

set rs=con.executes (sql) 'rs contains data to fill the listbox
set rs1=con.execute s(sql) 'rs1 contains data with saved options

<OPTION selected></OPTION>
<SELECT multiple>
<%while not rs.EOF%>
<%while not rs1.EOF%>
<% If rs1.fields("Opt ions")="Yes"%>
<OPTION selected><%=rs. Fields(0)%></OPTION>
<%else%>
<OPTION><%=rs.F ields(0)%></OPTION>

<%rs.MoveNext
%rs1.Movenext
Wend%>
</SELECT>
Hi, Thanks for the suggestions. but I've managed to get it to work using an array.
as suggested by hardman!
Feb 20 '07 #6
polymorphic
28 New Member
Hi,

I've run into the same situation described above. It seems that using an array as well as another recordset would be ideal for me. do you have a sample of the code you used to make this work?

Thanks,
cj
Jul 11 '07 #7
shweta123
692 Recognized Expert Contributor
Hi,

In case you are getting error in the the previous code?

Please refer the code below

<%
Dim rs,rs1,con
con.connections tring ="........."

'Open connection
con.open

'Sql for Filling Listbox

sql = "Select ............... ."
set rs = con.execute(sql )

'Sql for extracting user selected options
sql = "Select ............... ."
set rs1 = con.execute(sql )

while not rs.Eof%>
<SELECT id=select1 multiple name=select1>
<%
'Fill the Listbox
'Put the condition to Keep it Selected ot not

If rs1.Fields(2) = 'yes' %>
<OPTION selected><%rs.F ields(0)</OPTION>
<%else%>
<OPTION ><%rs.Fields(0) </OPTION>
end if

rs.movenext
rs1.movenext
wend
%>
Jul 12 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3595
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. I need to be able to send to a stored procedure the areas that the client has selected so these can be stored in the database.
5
1275
by: bigbuddha | last post by:
Hello, I have a form two multiple selectboxes. Firs one with options, second one empty I need to select a few items and hit an "add" button to get them in the second one. Preferably a "remove" button to. the second selectbox's name is "gen_list' cause i need it in for db handling. This might be something to keep in mind. If it's possible a re-useable funtion so i can use it for different
7
4110
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
0
2078
by: B | last post by:
Using Access2000, the sample code below is what I have been modifying and working on since the past week and I could not get it to work properly. What I wanted to accomplish: 1) read from a recordset and export to Excel 2) Excel is populated based from an ID (may possible be one or multiple) and renames the worksheet based from the ID 3) the code also format the fields The sample database may be downloaded at:
3
6048
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is "LabLocation_ID". With an existing lab, they then need to add the members for that lab. So, what I am trying to do is the following. With the FormView of the Lab open, the user will click a button to open a FormView (InsertMode) and add a new...
6
2356
by: JackM | last post by:
I have a multiple select input in a form that's being populated by a row from my database as such: <input type=\"checkbox\" name=\"subm\" value=\"$row\"> That part is working fine as I can check the displayed page using View Source and see that the value is the correct row number from the database. It is then being submitted on a form by $_POST method to another page where I want to evaluate the checkboxes and display the contents of...
19
3004
by: hexagram | last post by:
Hi guys good day, can anybody help for my problem The Scenario is A Listbox (ID) - Multiple Select - everytime i choose in the list box the following outbound textbutton and subform will retrieve in my form- the folliwng value will get from another form i have a code but i need to customize it because everytime i choose ID in my list box my value in subform is multiplying by row i mean the value in subform is duplicating
3
3579
by: davenumber40 | last post by:
I’m creating a small database in Access 2003(XP) to track issues during software testing. As far as databases go, it’s going to be a relatively small, short term project (No more than 20,000 records in the main table over about 2 months). I have a main table (Issues) that is populated by a form (IssueAdds). On my form there is a combobox to select Opened by (who created the record). That list is populated by a table called Contacts. Here...
0
9961
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
9800
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
11186
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...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5825
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...
2
4247
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.