Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional dropdown boxes and reading from SQL Server

Status
Not open for further replies.

KWade

MIS
Jul 14, 2003
14
US
Hi,

Here's my problem. I have an ASP page using VBScript and JavaScript and reading SQL Server 2000 database.

I want to display client and contact information on my webpage based on which 1)Client is selected and then 2) which contact for that client is selected.

SELECTION 1
===========
Client A
Client B
etc...

if Client A is selected then read from the DB and retrieve all of the Contacts for Client A and display in another dropdown selection list.

SELECTION 2
Contact 1
Contact 2
etc... for (Selected - Client A)

Once the contact is selected from SELECTION 2 then
display addresses, phone numbers etc...

I would like to populate text boxes that have already been
defined on default.asp but I just can't seem to figure it out.

I have managed to get the Contacts populated into a dynamic dropdown selection box using an inline form but I can't figure out how to get the other information.


<%@ LANGUAGE=&quot;VBScript&quot; %>
<!-- METADATA Type=&quot;TypeLib&quot; File=&quot;c:\program files\common files\system\ado\msado15.dll&quot; -->
<!--#include virtual=&quot;/projects/project/IASUtil.asp&quot;-->

<%
Set Conn1=Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn1.Open &quot;Provider=SQLOLEDB;Integrated Security=SSPI;Initial Catalog=nnn;Data Source=nnn&quot;
Set RS1=Conn1.Execute(&quot;asp_spProjectDataSheet&quot;)

%>
<SCRIPT language=&quot;JavaScript1.2&quot;>


function getIframe()
{
document.form1.contact.value=parent.iframe1.document.form2.elements[0].value;

}

</script>

<TABLE border=&quot;0&quot; cellspacing=&quot;0&quot; bgcolor='f0f0f0' width=&quot;100%&quot;>
<tr>
<TD>CLient: </td>
<td>
<select name=&quot;nclient&quot; style=&quot;Width:200&quot; onchange='loaddetail(this.value);document.getElementById(&quot;iframe1&quot;).src=&quot;getcontacts.asp?ClientID=&quot;+ this.value'>
<OPTION value='' selected>Select a client...
<%While Not RS1.EOF%>
<OPTION value=&quot;<%=trim(RS1(&quot;ClientID&quot;))%>&quot;>
<%=trim(RS1(&quot;Name&quot;))%>
<%
RS1.MoveNext
Wend
RS1.Close
Set RS1=Nothing
'Conn1.Close
%>
</select>
</td>
</tr>
<tr>
<TD>Contact:</td>
<td bgcolor='f0f0f0'><iframe id=&quot;iframe1&quot; name='iframe1' FRAMEBORDER=0 SCROLLING='no' HEIGHT=40></iframe></td>
</tr>
</table>


/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
getcontacts.asp

<body style=&quot;background:#f0f0f0 none&quot; leftmargin=0>
<!-- <% response.write(&quot;The passed variable is: &quot; & request(&quot;ClientID&quot;) )%> -->
<!-- METADATA Type=&quot;TypeLib&quot; File=&quot;c:\program files\common files\system\ado\msado15.dll&quot; -->
<form name=&quot;form2&quot;>
<!-- ////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<!-- Used with Project Data Sheets -->
<!-- ////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<%


set dbCon=Server.CreateObject(&quot;ADODB.Connection&quot;)
set MyCommand = Server.CreateObject(&quot;ADODB.Command&quot;)

dbCon.Open &quot;Provider=SQLOLEDB;Integrated Security=SSPI;Initial Catalog=nnn;Data Source=nnnn&quot;
MyCommand.ActiveConnection=dbCon

MyCommand.CommandType=adCmdStoredProc
MyCommand.CommandText = &quot;asp_spPDataSheetContacts&quot;
MyCommand.Parameters.Append MyCommand.CreateParameter(&quot;@inpClientID&quot;, adChar, adParamInput, 32, request(&quot;ClientID&quot;))
set rs = MyCommand.Execute

if not rs.eof then
response.write &quot;<select name='contact'>&quot;
while not rs.EOF
response.write &quot;<option value='&quot; & trim(rs(&quot;ContactID&quot;))& &quot;'>&quot; & trim(rs(&quot;ContactFullName&quot;))
rs.MoveNext
wend
response.write &quot;</select>&quot;
rs.close
set rs=nothing
end if
%>
</form>
</body>



 
break it into sub routines

1. show form w/ client names
2. get contact
3. show new form with details

then the main code block is just a check to see what is submitted

if nothing submitted and nothing set then
call show_form
else if client set
call get_contact
else if client set and contact set
call show_details_form
end if



Bastien

cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top