473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Populating a multiple select box from a database

37
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 5285
shweta123
692 Expert 512MB
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.Fields(0)%></OPTION>

<%rs.MoveNext
Wend%>
</SELECT>
Feb 16 '07 #2
ozzii
37
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.Fields(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 Expert 2GB
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 Expert 512MB
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.executes(sql) 'rs1 contains data with saved options

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

<%rs.MoveNext
%rs1.Movenext
Wend%>
</SELECT>
Feb 19 '07 #5
ozzii
37
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.executes(sql) 'rs1 contains data with saved options

<OPTION selected></OPTION>
<SELECT multiple>
<%while not rs.EOF%>
<%while not rs1.EOF%>
<% If rs1.fields("Options")="Yes"%>
<OPTION selected><%=rs.Fields(0)%></OPTION>
<%else%>
<OPTION><%=rs.Fields(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
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 Expert 512MB
Hi,

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

Please refer the code below

<%
Dim rs,rs1,con
con.connectionstring ="........."

'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.Fields(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
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. ...
5
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"...
7
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
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...
3
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...
6
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...
19
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.