PDA

View Full Version : Two Combo Boxes


Abd
06-11-2003, 11:17 AM
Hi All,

I have gone through some thread in this forum but still I still need some help. I have got two Combo Boxes and what I want is when a user select an item in the first Combo Box, the second Combo Box should only display items belonging to the items selected in the first Combo. E.g

1. Engineering First Combo Box
2. Science



1. Electrical Engineering Second Combo Box
2. Mechanical Engineering
3. Microbiology
4.Chemical Engineering
5. Biochemistry

Considering the above when a user select Engineering from first Combo Box only Engineering related items should be displayed in second Combo Box. And both Combo Boxes data are from the Database.

thanks

Abd

raf
06-11-2003, 11:48 AM
What didn't you understand in the threads you read?

How is the database organised? Can you tell us which tables/columns you have?

Abd
06-11-2003, 02:38 PM
Hi

the fisrt and second Combo Box items are both in the same table and ofcourse diffrent column, infact I am able to populate the Combo Boxes with data from the database successfully, and am working with Oracle Database

Abd

raf
06-11-2003, 04:09 PM
Post the code to populate the two dropdowns here. I'll change it into a multiputpose page .

Abd
06-11-2003, 07:52 PM
raf,


first Combo => Nature of Service Category

second Combo => Nature of Service Sub Category

Bellow is the code;


<html>
<head>
<meta name="GENERATOR" Content="ASP Express 2.2">
<title>New Customer</title>

<script language="JavaScript" src="pupdate.js">

/*
Popup calendar
*/

</script>
</head>

<%

session("logintime")=Now()
session("crmdate")=date()
%>

<% title= TRIM( Request.form("title") ) %>
<% city= TRIM( Request.form("city") ) %>
<% msisdn= TRIM( Request.form("msisdn") ) %>
<% firstname= TRIM( Request.form("firstname") ) %>
<% state= TRIM( Request.form("state") ) %>
<% job_description= TRIM( Request.form("job_description") ) %>
<% lastname= TRIM( Request.form("lastname") ) %>
<% country= TRIM( Request.form("country") ) %>
<% type_service= TRIM( Request.form("type_service") ) %>
<% address1= TRIM( Request.form("address1") ) %>
<% telephone= TRIM( Request.form("telephone") ) %>
<% contract_status= TRIM( Request.form("contract_status") ) %>
<% address2= TRIM( Request.form("address2") ) %>
<% fax= TRIM( Request.form("fax") ) %>
<% e_mail= TRIM( Request.form("e_mail") ) %>
<% street= TRIM( Request.form("street") ) %>
<% customer_code= TRIM( Request.form("customer_code") ) %>

<% assignedto= TRIM( Request.form("txtassignedto") ) %>
<% activity_type= TRIM( Request.form("activity_type") ) %>
<% category= TRIM( Request.form("category") ) %>
<% category_id= TRIM( Request.form("category_id") ) %>
<% acategory= TRIM( Request.form("acategory") )%>
<% acategory_id= TRIM( Request.form("acategory_id") )%>
<% sub_category= TRIM( Request.form("sub_category") ) %>
<% sub_category_id= TRIM( Request.form("sub_category_id") ) %>
<% asub_category= TRIM( Request.form("asub_category") ) %>
<% asub_category_id= TRIM( Request.form("asub_category_id") ) %>
<% summary= TRIM( Request.form("summary") ) %>
<% description= TRIM( Request.form("description") ) %>
<% date_opened= TRIM( Request.form("date_opened") ) %>
<% assignedto= TRIM( Request.form("txtassignedto") ) %>
<% due_comp_date= TRIM( Request.form("due_comp_date") ) %>
<% created= TRIM( Request.form("created") )%>
<% priority= TRIM( Request.form("priority") )%>
<% status= TRIM( Request.form("status") )%>
<% source= TRIM( Request.form("source") )%>
<% adue_comp_date= TRIM( Request.form("adue_comp_date") )%>
<% created_by= TRIM( Request.form("created_by") ) %>
<% created_by= TRIM( Request.form("created_by") )%>
<% comment=TRIM( Request.form("comment") )%>
<% acomment= TRIM( Request.form("acomment") )%>
<% tdaydate= TRIM( Request.form("tdaydate") )%>


<%
Set Con = Server.CreateObject("ADODB.Connection")
Con.Open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
'Set RS = Server.CreateObject("ADODB.Recordset")
'Set RST = Server.CreateObject("ADODB.Recordset")


IF msisdn <> "" THEN
MyCom = "INSERT into customer_all(title,firstname,lastname,address1,address2,street,city,state,country,telephone,fax,e_ma il,msisdn,job_description,type_service,customer_code,contract_status)VALUES('"&title&"','"&firstname&"','"&lastname&"','"&address1&"','"&address2&"','"&street&"','"&city&"','"&state&"','"&country&"','"&telephone&"','"&fax&"','"&e_mail&"','"&msisdn&"','"&job_description&"','"&type_service&"','"&customer_code&"','"&contract_status&"')"

SQLsrvreq = "INSERT into service_request(assignedto,summary,category,category_id,sub_category,sub_category_id,date_opened,due _comp_date,firstname,lastname,msisdn,type_service,contract_status,priority,status,source,created_by, comment,tdaydate)VALUES('"&assignedto&"','"&summary&"','"&category&"','"&category_id&"','"&sub_category&"','"&sub_category_id&"','"&date_opened&"','"&due_comp_date&"','"&firstname&"','"&lastname&"','"&msisdn&"','"&type_service&"','"&contract_status&"','"&priority&"','"&status&"','"&source&"','"&created_by&"','"&comment&"','"&tdaydate&"')"

SQLact = "INSERT into activity(activity_type,acategory,acategory_id,asub_category,asub_category_id,description,firstname,l astname,msisdn,type_service,contract_status,created,created_by,tdaydate)VALUES('"&activity_type&"','"&acategory&"','"&acategory_id&"','"&asub_category&"','"&asub_category_id&"','"&description&"','"&firstname&"','"&lastname&"','"&msisdn&"','"&type_service&"','"&contract_status&"','"&created&"','"&created_by&"','"&tdaydate&"')"

Con.Execute MyCom
Con.Execute SQLsrvreq
Con.Execute SQLact

End If
Con.Close
Set Con = Nothing


%>

<%
IF msisdn <> "" THEN

Set Con = Server.CreateObject("ADODB.Connection")
Con.Open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set RS = Server.CreateObject("ADODB.Recordset")
Set RST = Server.CreateObject("ADODB.Recordset")



RS.Open "select customer_id from customer_all where msisdn = '" &msisdn& "' ", Con

customer_id = RS.Fields("customer_id")

SQLsrv = "UPDATE service_request SET customer_id = '"&customer_id&"' where msisdn= '"&msisdn&"' "

Con.Execute SQLsrv



RST.Open "select srv_req_id from service_request where msisdn = '" &msisdn& "' ", Con

srv_req_id = RST.Fields("srv_req_id")

SQLactsrv = "UPDATE activity SET srv_req_id = '"&srv_req_id&"' where msisdn= '"&msisdn&"' "

Con.Execute SQLactsrv

end if

%>


<%
if request.form("action") = "Return to Search Page" then
'user = session("user")
'pasword = session("password")
Response.Redirect"csr.asp"
end if
%>

<%
'if session("securityprofile") >= "1" Then 'browses straight to this page, the value will be 0.
'response.write("Welcome")
'Response.Expires = -1500

username = session("user")

%>



<body>
<img src="globacom.gif">
3
<br>
<SCRIPT language=JavaScript src="camden.js" type=text/javascript></SCRIPT>

<form Name="form1" action="customer.asp" method="post">

<table cellpadding="2" cellspacing="2" border=0>
<tr>
<td align="left" valign="top"><b>Title:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Dr">Dr</option>
</select>
</td>
<td align="left" valign="top"><b>Firstname: </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="firstname" type="Text" size="15">
</td>

<td align="left" valign="top"><b>Lastname: </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="lastname" type="Text" size="15">
</td>

</tr>
<tr>
<td align="left" valign="top"><b>Mobile No:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="msisdn" type="Text" size="15" MAXLENGTH="11">
</td>
<td align="left" valign="top"><b>Service Type:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="type_service">
<option>Prepaid</option>
<option>Postpaid</option>
</select>
</td>
<td align="left" valign="top"><b>Contract Status: </b><select name="contract_status">
<option>Activated</option>
<option>Interested</option>
<option>Deactivated</option>
<option>Suspended</option>
</select>
</td>
</tr>
<tr>
<td align="left" valign="top"><b>Telephone:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="telephone" type="Text" size="15">
</td>
<td align="left" valign="top"><b>Fax:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="fax" type="Text" size="15">
</td>
<td align="left" valign="top"><b>Street:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="street" type="Text" size="15">
</td>
</tr>
<tr>
<td align="left" valign="top"><b>City:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="city">
<option>Lagos</option>
<option>Ibadan</option>
<option>Port Harcourt</option>
<option>Abuja</option>
<option>Kano</option>
</select>
</td>
<td align="left" valign="top"><b>State:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="state">
<option>Lagos</option>
<option>Oyo</option>
<option>Rivers</option>
<option>Abuja</option>
<option>Kaduna</option>
</select>
</td>
<td align="left" valign="top"><b>Country: </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="country">
<option>Nigeria</option>
<option>Ghana</option>
<option>South Africa</option>
</select>
</td>

</tr>
<tr>
<td align="left" valign="top"><b>Address 1: </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="address1" type="Text" size="15">
</td>
<td align="left" valign="top"><b>Address 2:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="address2" type="Text" size="15">
</td>
<td align="left" valign="top"><b>Job Description: </b><input name="job_description" type="Text" size="15">
</td>
</tr>
<tr>
<td align="left" valign="top"><b>E-Mail:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="e_mail" type="Text" size="15">
</td>
<td align="left" valign="top"><b>Customer Code:</b> <input name="customer_code" type="Text" size="15">
</td>
<td align="left" valign="top"></td>
</tr>



</table>

<hr>


<%
'Populating Assigned To Combo Box from DB


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select department, description from assignedto")


response.write "<b>Assigned To:</b>&nbsp;<select name='txtassignedto'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("department")&""">"&rs("department")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


<%
'Populating Activity Type ComboBox from DB

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select activity_type from activities where activity_type <> 'NULL' ")


response.write "<b>Activity Type:</b>&nbsp;<select name='activity_type'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("activity_type")&""">"&rs("activity_type")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

<br><br>


<%
'Populating Nature of Services Category

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select DISTINCT category from services")

test=rs.Fields("category")

response.write "<b>Nature Of Service Category:</b>&nbsp;<select name='category' onclick='submit();'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("category")&""">"&rs("category")&" </option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<%
'Populating Activity Category

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select DISTINCT acategory from activities")


response.write "<b>Activity Category:</b>&nbsp;<select name='acategory'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("acategory")&""">"&rs("acategory")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

<br><br>


<%
'Populating Nature of Services Sub Category

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set RS= Server.CreateObject( "ADODB.Recordset" )

sql="Select DISTINCT sub_category from services where sub_category='loginuser' "
sql=replace(sql,"loginuser",request.QueryString("test"))

RS.Open sql, oConn


response.write "<b>Sub Category:</b>&nbsp;<select name='sub_category'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("sub_category")&""">"&rs("sub_category")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


<%
'Populating Activity Sub Category

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select DISTINCT asub_category from activities where asub_category <> 'NULL' ")


response.write "<b>Activity Sub Category:</b>&nbsp;<select name='asub_category'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("asub_category")&""">"&rs("asub_category")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

<br><br>

<b>Nature Of Service Summary:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Activity Description:</b><br>

<TEXTAREA NAME="summary" ROWS=5 COLS=40></TEXTAREA>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


<TEXTAREA NAME="description" ROWS=5 COLS=40></TEXTAREA>

<br><br>

<b>Date Opened:</b> <input name="date_opened" value="<%=now()%>" type="Text" size="25">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b>Created:</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="created" type="Text" value="<%=now()%>" size="25">


<!-- <b>Due Completion Date:</b> <input name="adue_comp_date" type="Text" size="15"><a href="#" onClick="getCalendarFor(document.form1.adue_comp_date);return false"> <font color="red"><sub>[Choose Date]</sub></font></a> -->



<br><br>

<b>Due Completion Date:</b> <input name="due_comp_date" type="Text" size="15"><a href="#" onClick="getCalendarFor(document.form1.due_comp_date);return false"> <img src="cal.gif"></a>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b>Created By:</b><input name="created_by" type="Text" size="15" value="<%=username %>">


<br><br>

<b>Priority:</b>&nbsp;<select name="priority">
<option>Normal</option>
<option>Very High</option>
<option>High</option>
<option>Low</option>
</select>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<%
'Populating Status ComboBox

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select status from services where status <> 'NULL' ")


response.write "<b>Status:</b>&nbsp;<select name='status'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("status")&""">"&rs("status")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


<br><br>

<%
'Populating Source ComboBox

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"

Set rs=oConn.execute("Select source from services where source <> 'NULL' ")


response.write "<b>Source:</b>&nbsp;<select name='source'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("source")&""">"&rs("source")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b>Created By:</b><input name="created_by" type="Text" size="15" value="<%=username %>">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<br><br>

<b>Comment:</b><br>

<TEXTAREA NAME="comment" ROWS=3 COLS=35></TEXTAREA>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input name="tdaydate" type="Text" id="tdaydate" value="<%=date()%>" size="15" ReadOnly>

<center><input name="submit" type=submit value="Save" onClick="return Submit()"><input name="reset" type=reset value="Reset"></center>

<input type="submit" value="Return to Search Page" name="action">


</form>

</body>
</html>

raf
06-11-2003, 08:21 PM
Lott of code ...
I should go completely through it cause i see some things that can be optimised. For instance;
- try to avoid switching in and out asp-mode. Things like
<% some asp
%>
<br>
<br>
<%
...
%>

should be
<% ...
response.write("<br /><br />")
...
%>
- dont open and close the connection more then once on your page. Close recordsets and set them to nothing as soon as you can, but leave the connection open.
- all these variabels at the top, thats not necessary + in all textvalues you're going to insert, replace sigle quotes by two singlequotes (see sticky on tôp of this forum)
- you should put <%option explicit%> on top of the page, and dim all the variabels
- you can't use request.form and request.querystring on one form !
- check up on DSN-less connections + store the connectionstrings in an include (with .asp extension) Run a search here and you'll find plenty of threads about these issues
(we all needed to learn ;) and the more people go through your code, the faster you'll learn)

About the dropdowns
Before the second dropdown, check if there is a value in the formscollection for the first one. If there is one, select the values and use the value from the first dropdown as a criterium. If there isn't a value, skip it.
Like

'Populating Nature of Services Sub Category
If Len(request.form("category") > 0 then
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set RS= Server.CreateObject( "ADODB.Recordset" )

sql="Select DISTINCT sub_category from services where category='thecat'"
sql=replace(sql,"thecat",request.Form("category"))
' so the value that was selected, will be used as condition.
' i suppose it is a string-variable
RS.Open sql, oConn


response.write "<b>Sub Category:</b> <select name='sub_category'>"&vbcrlf

if rs.EOF = True then
response.write("Databaseproblem. The dropdown with sub-categorys could not be generated.")
else
while not rs.eof
response.write "<option value="""&rs("sub_category")&""">"&rs("sub_category")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf
end if
rs.close
set rs=nothing
end if


When i run such a select, i always order the records.

Just let us know if you need some more info.

Abd
06-12-2003, 10:06 AM
thanks raf,

when I ran the code it seams this part of the code is not working because for Populating Nature of Services Sub Category the Combo Box was empty, so I comment this part of the code;

'if Len(request.form("category") > 0) then

'end if

same result the second Combo Box was empty, but when I hard coded a value of the first Combo Box like this;

sql="Select DISTINCT sub_category from services where category='Bill Enquiry' " it returns a result.

So the problem is HOW to get the value of the first Combo Box to the where clause criterium of the second Combo Box.

Abd

raf
06-12-2003, 10:22 AM
The code from my previous post should work, but i don't know if you post the page to itself.

I see a lot of dropdowns there, so i'm not sure what you're trying to do and if they are related and stuff.

Normally, your code for a multiputpose page will look

<%
connectionstrings

code for the first dropdown where <select name="category" ...

if Len(request.form("category") > 0 then 'so if there is a value for category selected
code for the second dropdown with
sql="Select DISTINCT sub_category from services where category='thecat'"
sql=replace(sql,"thecat",request.Form("category"))
to get the selected categry as conddition
end if

rest of code
close connection
%>

And the form should post to itself. If you post it to another page (no problem), then you just need to tale out the code for the second dropdown (+ connectionstrings) and store that in the second page.

Abd
06-12-2003, 11:45 AM
raf,

your last post is a little confusing to me, you have combine the code for populating the first and second Combo together, I didn't get that, can you pls use the code for generating both Combo Boxes for your illustration, and I am actually posting to itself, bellow is the code;

<%
'Populating Nature of Services Category ----=> First Combo Box

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set rs=oConn.execute("Select DISTINCT category from services")

response.write "<b>Nature Of Service Category:</b> <select name='category' onclick='submit();'>"&vbcrlf

while not rs.eof
response.write "<option value="""&rs("category")&""">"&rs("category")&" </option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>



<%
'Populating Nature of Services Sub Category ----=>2nd Combo Box


If Len(request.form("category") > 0) then
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set RS= Server.CreateObject( "ADODB.Recordset" )

sql="Select DISTINCT sub_category from services where category='thecat'"
sql=replace(sql,"thecat",request.Form("category"))
' so the value that was selected, will be used as condition.
' i suppose it is a string-variable
RS.Open sql, oConn


response.write "<b>Sub Category:</b> <select name='sub_category'>"&vbcrlf

if rs.EOF = True then
response.write("Databaseproblem. The dropdown with sub-categorys could not be generated.")
else
while not rs.eof
response.write "<option value="""&rs("sub_category")&""">"&rs("sub_category")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf
end if
rs.close
set rs=nothing
end if
%>

raf
06-12-2003, 01:16 PM
Hmm. We're missing something here.

Just to make sure:
- you heve a table (services) with this structure
category - sub_category
engineering - Electrical Engineering
engineering - Mechanical Engineering
engineering - Chemical Engineering
science - Microbiology
science - Biochemistry
The category box will show engineering and science option. If you select science, then the second box will show Microbiology and biochemistry
Right?
- you are sure there are subcategorys for all categorys
- the first time the page loads, you will only see the first dropdown (category).
- as soon as you select an option from the category-dropdown, the page will be submitted --> maybe the problem is here. Using onclick="submit();", well this is tricky. If you click the arrow of the dropdown, the page is submitted (since youclicked on the formelement), but there is no category selected, so it might post some default value (normally it should post the value of the first category. Now the check is Len (request.form("category") (length of the value) but the dropdown will post a value.
Try to hold the mousebuttondown when you click on the arrow and then move the pointer to the option you want and then release the button.
(onclick-submit looksnice etc but it produces a lot of 'false hits')
If that doesn't work, insert this right after the sql=replace ... line

response.write sql
response.write("category = " & request.form("category")
response.end

to print the executed statement and value from the category dropdown.
- the second time that the page loads, you should see the subcategory dropdown


modified code:

<%
'Populating Nature of Services Category ----=> First Combo Box

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "DSN=ABD;UID=;PWD=;PWD=;DATABASE=abd"
Set rs=oConn.execute("Select DISTINCT category from services")

response.write "<b>Nature Of Service Category:</b> <select name='category' onclick='submit();'>"&vbcrlf

while not rs.eof
response.write "<option value="""&rs("category")&""">"&rs("category")&" </option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
'Populating Nature of Services Sub Category ----=>2nd Combo Box

If Len(request.form("category") > 0) then
Set RS= Server.CreateObject( "ADODB.Recordset" )

sql="Select DISTINCT sub_category from services where category='thecat'"
sql=replace(sql,"thecat",request.Form("category"))
' so the value that was selected, will be used as condition. i suppose it is a string-variable
'#######
'Uncomment this for debugging purposes. From here

'response.write sql
'response.write("category = " & request.form("category")
'response.end

'till here
'#######

RS.Open sql, oConn


response.write "<b>Sub Category:</b>" &vbcrlf

if rs.EOF = True then
response.write("Databaseproblem. The dropdown with sub-categorys could not be generated.")
else
response.write "<select name='sub_category'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("sub_category")&""">"&rs("sub_category")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf
end if
rs.close
set rs=nothing
end if
%>