Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2007, 06:10 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamicly filling drop down

I have 2 drop down boxes on a page (or need to have 2) I am filling the forst one when the page loads from a table in my DB I want the secound box to be empty until a selection is made from the first box then based on the record number from the DB i will fill the second box from a differnt table in the DB
What i have done so far is opend the DB at the open of the page, then I create the first box when needed in the Html portion of my page...


<Tr><TD>Show Location</TD><TD><SELECT NAME="ShowProp">
<% While not objRS.EOF
    Response.write "<Option>" & objRS("PropertyName")
    objRS.MoveNext
Wend
%>
</option></SELECT></TD>

This part is working fine Im jsut not sure how to use the OnChange event to read from the record set again to get the record ID and then use that to pull the information from a differnt record set. The only way I have come up with doing it so far is to just wrtie vbscript in the Onchance event that reopens the tables and then do a search on the DB from there to match the prop name then get the record id then get the luist i need from the other table and I am hoping there is a better way to do this.. Hopefuly I have explained this well enought any help would be wounderful
-Jim
 
Old June 18th, 2007, 06:54 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Put this in your select tag:
onchange="postAndReload();"

This is the head of your doc between <script> tags:
  function postAndReload(whichLevel)
  {
     //do any JS you want here, then post the form
     formName.submit();
  }

Now in the top of your page somewhere detect if the form has been posted. If you have placed the id of the record you wish to query with in your option tag (it doesnt look like you have, you need a value inside each option tag. Also you should place </option> tags inside your loop) use it to get you new results.

Change you loop to something like:
<Tr>
 <TD>Show Location</TD>
 <TD>
<% if not objRS.Eof then %>
        <SELECT NAME="ShowProp">
<% While not objRS.EOF %>
           <Option value="<%= objRS("uniqueID") %>"><%= objRS("PropertyName") %></option>
<% objRS.MoveNext
        Wend
     else
        response.write "no records found"
     end if %>
        </SELECT></TD>


Wind is your friend
Matt
 
Old June 21st, 2007, 01:29 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help. Im not useing JS i am useing VBscript but you pointed me where I needed to go. The thing I am running into with this now is when i repost the form all my text boxes and drop downs are coming back blank I am trying to refill them like

<TR><td>Guest Name</TD><TD><INPUT type="text" NAME="GuestName" VALUE="<% Request.form("GuestName")%>"></TD>
but they are still coming up blank and I am not sure why I am not getign any errors returned they just arnt filling in. This may seem like a very basicv issue but I am Very New to ASP if you have any ideas on this please share them.


Thank you very much for the help so far

Jim


 
Old June 21st, 2007, 03:36 PM
Authorized User
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok so after reading what I posted I see what i did wrong... Thanks again for your help
 
Old June 26th, 2007, 09:54 AM
Authorized User
 
Join Date: Sep 2006
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to misskaos
Default

Quote:
quote:Originally posted by JAdkins
 Ok so after reading what I posted I see what i did wrong... Thanks again for your help

Try this

<HTML>
<HEAD>
<script language="VBScript">
Sub PopulateSecondDropDown
Dim TheForm
Set TheForm=Document.forms("YourFormName")
TheForm.SecondDropDown.value=""
TheForm.action="YourPageName.asp"
TheForm.submit
End Sub
</script>


<Tr>
 <TD>Show Location</TD>
 <TD>
<%if not objRS.Eof then%>
<SELECT NAME="ShowProp" onchange="PopulateSecondDropDown();">
<%While not objRS.EOF%>
<option value="<%=objRS("uniqueID")%>"><%=objRS("PropertyN ame")%>
</option>

<%
objRS.MoveNext
Wend
%>
</SELECT>

<%
else
response.write "no records found"
end if
%>
</TD>
<%
dim RS
dim count
Dim objConn

set ObjConn = server.CreateObject("adodb.Connection")
ObjConn.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("dB.mdb")

SelectedProp = Request.Form("ShowProp")
set RS = server.createObject("adodb.recordset")
SQL = "SELECT * from TABLENAME where recID = '" & SelectedProp & "'"
RS.open SQL,ObjConn
if not RS.EOF then
%>

<TD>SHOW OTHER RECORDS [DROP DOWN]</TD>
<TD>
<SELECT NAME="ShowOtherRecords">

<%While not RS.EOF%>

<option value="<%=RS("uniqueID")%>"><%=objRS("OtherColumnN ame")%>
</option>
</SELECT>

<%
else
response.write "No value obtained from first drop down."
end if
%>

</TD>
</TR>


T.B.
misskaos99@yahoo.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Acces dynamicly(with JS) made <div> in code swifty_programmer Javascript 3 June 19th, 2007 12:36 AM
Adding controls dynamicly Paula222 Access VBA 21 February 9th, 2006 05:29 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
dynamicly name a record set mat41 Classic ASP Professional 6 March 16th, 2004 03:50 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.