473,405 Members | 2,187 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,405 software developers and data experts.

asp drop down list based on table

Hi there I want to know how to add a drop down list based on value from a table in an asp form. Then I want the user to be able to submit the form, and the drop down list value that they have selected to be stored in a different table.

Does anyone know how to do this, I present I am using the code below, which does create the drop down list, but then I not sure how to add its value to another table in my database ( Acesss)

If anyone can help I would be very grateful!!!!

<%@ Language=VBScript %>
<%Option explicit
Dim oRs, conn, connect, strSQL

set conn=server.CreateObject ("adodb.connection")
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("courses.mdb") & ";Persist Security Info=False"
conn.Open connect

%>
<html>
<head>
<title>Example combo box</title>

<script language="javascript">
<!--

function dept_onchange(frmSelect) {
frmSelect.submit();
}

//-->
</script>
</head>
<body>
The following was selected : <%=Request.Form ("courses")%>

<form name="frmSelect" method="Post" action="select.asp">
<SELECT name=courses LANGUAGE=javascript onChange="return dept_onchange(frmSelect)">
<%
Set oRs=Server.CreateObject("adodb.recordset")
strSQL = "SELECT DISTINCT CourseName FROM tblCourses ORDER BY CourseName"
oRs.Open strSQL, conn

Do while not oRs.EOF
if Request.Form("courses") = oRs("CourseName") then 'if this is the selected one then display as selected
Response.Write "<OPTION VALUE = '" & oRS ("CourseName") & "' SELECTED>"
Response.Write oRs("CourseName") & "</Option>"
oRs.MoveNext
else
Response.Write "<OPTION VALUE = '" & oRs ("CourseName") & "'>"
Response.Write oRs("CourseName") & "</Option>"
oRs.MoveNext
end if
loop
%>
</SELECT>
</form>

</body>
</html>
Mar 21 '08 #1
1 3905
DrBunchman
979 Expert 512MB
Hi deerick,

You need to write a bit of script to INSERT your data in to the other table. Once you've written that you need it to run when your form is submitted. The easiest way to do this is to change your forms action property to a different page, say InsertData.asp, then re-direct back to your original page once it has done it's work on the database. I've written a quick example below for you to take a look at.

In your first page (select.asp) set the action of your form:
Expand|Select|Wrap|Line Numbers
  1. <form name="frmSelect" method="Post" action="InsertData.asp">
  2.  
When the drop down is selected the form will submit and go to the following page:

InsertData.asp:

Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. Dim conn, connect, strSQL
  3.  
  4. set conn=server.CreateObject ("adodb.connection")
  5. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("courses.mdb") & ";Persist Security Info=False"
  6. conn.Open connect
  7.  
  8. strSQL= " INSERT INTO table (Column1) VALUES ('" & Request.Form("courses") & "') "
  9.  
  10. conn.Execute strSQL
  11.  
  12. Response.Redirect("select.asp")
  13. %>
  14.  
Does this help at all? Let me know how you get on.

Dr B
Mar 21 '08 #2

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

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
2
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
4
by: riteshjain82 | last post by:
Hi, I am maintaining a site which is written in ASP. Now i have to create some new pages. In one page we have a table with many rows. Now, I want to enable or disable(showing and hiding also) 2...
0
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
8
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
1
by: robertrozarioa | last post by:
Hi , I am new to ACCESS.please help me out. I am designing a database.I have 3 tables, and have 3 forms based to collect data. 1. Individual ( fields are Name, Email, Status) Status is a...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
0
by: jaeden99 | last post by:
I have a two drop down list box. The first contains district name(district id is the value) and the the second will contain the user name based on the district selected in the first drop down list....
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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,...
0
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...
0
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...
0
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,...

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.