Click to See Complete Forum and Search --> : Populating Dropdown list based on the other dropdownlist


praveenhathwar
03-11-2009, 01:02 AM
Hi, Im pretty new to asp and also to the forum...
I have a problem in retreiving the data to a dropdown list (combo box) from database based on the previous dropdownlist's data. Can any body help me in sorting out the issue...

Here is my code...


<HTML>
<HEAD>
<script language="JavaScript">
var clockID = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var tDate = new Date();
document.theClock.theTime.value = ""
+ tDate.getHours() + ":"
+ tDate.getMinutes() + ":"
+ tDate.getSeconds();

clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}

function checkform()
{
if (document.form1.mlfrom.value=='')
{
alert('Please enter the name');
document.form1.mlfrom.focus();
return false;
}
else if (document.form1.cont.value=='')
{
alert('Please enter the Contact No / Extension');
document.form1.cont.focus();
return false;
}
else if (document.form1.comdesc.value=='')
{
alert('Please enter the complaint description');
document.form1.comdesc.focus();
return false;
}
return true;
}

function trimmlfr()
{
document.form1.mlfrom.value =
document.form1.mlfrom.value.replace(/ /g, "");
}
function ext()
{
document.form1.cont.value =
document.form1.cont.value.replace(/ /g, "");
}
function cd()
{
document.form1.comdesc.value =
document.form1.comdesc.value.replace(/ /g, "");
}
function CheckKeyCode()
{
if( (event.keyCode == 13 || event.keyCode == 9 || event.keyCode == 8 || event.keyCode == 37 || event.keyCode == 39) ||
(event.keyCode >= 48 && event.keyCode <= 57) ||
(event.keyCode >= 96 && event.keyCode <= 105) ) {
return true; }
else {
return false;
}
}
function hidefield()
{
if(document.form1.location.selectedIndex == 0 )
{
document.form1.astno.disabled = true;
document.getElementById("A").style.display='block';
}
else if(document.form1.location.selectedIndex == 1 )
{
document.form1.astno.disabled = false;
document.getElementById("A").style.display='true';
}
}
function assests()
{

How can i connect to database here??? What is the method to do it ? I have no idea... :(

}
</script>


<TITLE>Company Name</TITLE></HEAD>
<BODY bgcolor=silver onload="StartClock()" onunload="KillClock()">
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.open "filedsn=C:\proj\Maintenance\mtrmnd"

set rs2 = Server.CreateObject("ADODB.recordset")
sq = "Select * from division"
rs2.Open sq,conn
%>
<form name="theClock"><input type=text name="theTime" size=8></form>
<center><H1>Company Name</H1></center>
<center><H3>Complaint Register</H3></center>
<table align=center border=0>
<tr>
<td>From</td>
<td><form action="Regicomp.asp" method="post" id=form1 name=form1 onsubmit="return checkform();">
<input name=mlfrom onChange="trimmlfr()"></td>
</tr>
<tr>
<td>Contact No / Extension</td>
<td><input name=cont onChange="ext()" onkeydown="return CheckKeyCode()"></td>
</tr>
<tr>
<td>Nature of Complaint</td>
<td>
<select name="location" onchange="hidefield()">
<option selected>Non Production
<option>Production
</select>
</td>
</tr>
<tr>
<td>Division</td>
<td><select name="div">
<% Do while not rs2.EOF %>
<option><%Response.Write(rs2.Fields (1)) %></option>
<% rs2.MoveNext
Loop %>
</select>
</td>
<tr id="A">
<td>Asset Number</td>
<td><select name="astno" onchange="assests()">
<option> </option>
</select>
</td>
</tr>
<tr>
<td>Complaint Description</td>
<td><textarea name=comdesc rows=8 cols=40></textarea></td>
</tr>
<tr>
<td><input type = submit value="Register Complaint" name=regis></td>
<td><input type = reset value="Clear" name=cls></td>
</tr>
</form>
</table>
</BODY>
</HTML>

bwkaz
03-11-2009, 01:10 AM
Um, given that this is a Linux forum, you probably won't get very much help on your (Windows-only) ASP question. I know I don't have much of a clue about ASP...

(It might help to use code tags as well, so your indentation gets preserved. But it may not do much good anyway; see above.)

praveenhathwar
03-11-2009, 01:18 AM
Hmmm, :) Thats true...

I have no option. I posted in other forums also. As it is of urgent, i thought of testing my luck in this forum (coz i ve seen some of asp questions raised previously...)

Anyway thanks for your reply... :)

bwkaz
03-11-2009, 01:31 AM
Well, hopefully someone sees it that does know more about ASP. I've edited your post and added code tags ( and ), so in case someone does know ASP, they can at least read the code. :)

praveenhathwar
03-11-2009, 01:42 AM
OK... Thanks a lot. Actually it is Javascript. If i get the solution with that, it is enough...

Bryon Speede
03-12-2009, 12:36 PM
I have done this in pure JS before. I had to load an array with all possible information for the second drop down and select what to display using an onclick event or something similar. It has been a long time since I did this and I have since moved to an AJAX solution. With AJAX just make the call to the database for the relevant information for the second drop down after the first dropdown is selected. I don't have a code example handy, but hopefully this points you in the right direction.

praveenhathwar
03-13-2009, 04:37 AM
Fine Bryon,
If i ve to switch to Ajax, then i ve to make a lot of changes in my project which is hectic work... Do you ve any other possible idea so that a little modification is involved...

Thanks in advance :rolleyes: