472,331 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 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 5239
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...
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...
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. ...
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...
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\"...
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...
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...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.