Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 July 30th, 2003, 06:52 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Synchronising combo boxes

hello people,I'm going mental,:(:(
i'm trying to synchronise 2 combo boxes but am having difficulty with function calls I think
The function call I'm using to get from the first combo box to the second is wrong.Can anybody spot what it is ?

It is giving the folowing error
line 19 object doesn't support this property or method
But I still think it's something to do with the onchange handler in the first combo box because line 19 is just Set catRs=Server.CreateObject("ADODB.RecordSet")

Anyway this is the code which is tantalisingly close to being correct , I think:)

<html>
<head>
<title>Inputting a new Question</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT Language="JavaScript">
 function mySubmit()
  {
  }
  function submit1()
  {
  sel.form.submit();
  }
 </SCRIPT>
</head>
<body>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
  Set catConn=Server.CreateObject("ADODB.Connection")
  Set catRs=Server.CreateObject("ADODB.RecordSet")
  catConn.Open("mm32")
  catRs.Open "SELECT * From Law", catConn, 1, 2
  catRows = catRs.getRows
  catRs.Close
Set catRs = nothing
catChosen = Request.Form("CategorySelect")
showSubcat = False
If (("X" & catChosen) <> "X") AND (catChosen <> "NONE") Then
    catChosen = CInt(catChosen)
   showSubcat = True
     Set subRS = catConn.Execute("SELECT componentNo FROM Component" _
                            & " WHERE lawNo=" & catChosen _
                            & " ORDER BY componentNo")
    subRows = subRS.getRows
    subRS.Close
    Set subRS = nothing
End If
catConn.Close
Set catConn = nothing
%>

<P>
Which law does your question pertain to?<P>
First select a law and then, when the list of components
appears, select a component:<P>
<form name="form1" action="http://pertinax.cms.shu.ac.uk/mmtec/mm32/Inputaquestion4.asp" method="post" >
<SELECT Name="CategorySelect" MULTIPLE size=10
        onChange="document.form1.Submit1();">
    <OPTION Value="NONE">-- choose a category below--
<% For cnum = 0 To UBound(catRows,2) %>
    <OPTION Value="<%= catRows(0,cnum) %>"
            <% If catRows(0,cnum) = catChosen Then %>
            SELECTED
            <% End If %>
            ><%= catRows(1,cnum) %>
<% Next %>
</SELECT>
<SELECT Name="SubcategorySelect" MULTIPLE Size=10>
<% If showSubcat = False Then %>
    <OPTION Value="0">-- no subcategories yet --
<% Else %>
    <OPTION Value="0">-- choose a subcategory below--
    <% For cnum = 0 To UBound(subRows,2) %>
        <OPTION Value="<%= subRows(0,cnum) %>"><%= subRows(1,cnum) %>
    <% Next %>
<% End If %>
</SELECT>
  <p>
     <input type="submit" name="Submit" value="Submit" onClick="mySubmit()">
    </p>
  </form>
  <p><strong></strong> </p>
</body>
</html>


andrew
 
Old August 1st, 2003, 01:25 PM
Registered User
 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tcasp
Default

Andrew:

        I am doing the same thing,I can populate the first box with main categories and second with subcategories but at the moment I want to display the chosen subcategory information on the next page.When I will be done with this I will be able to help you.
tcasp

 
Old August 5th, 2003, 06:59 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No worries Tcasp:):D:):):),here is the code.By the way it's got a bit of javascript validation which you may or may not want
just change my fields such as lawNo and ComponentNo to your field names.Your DSN ,server path and file name and all that kind of stuff must be different aswell.
<html>
<head>
<TITLE>Category and Subcategory Drop Down Lists Demonstration</TITLE>
<title>Inputting a new Question</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT Language="JavaScript">
 function lawChanged()
  {
   if(form1.LawSelect.selectedIndex==0){ alert("You must choose a Law")}
   else
    {
     form1.action="http://pertinax.cms.shu.ac.uk/mmtec/mm32/HughInputAQuestion1.asp"
     form1.submit()
    }
  }

 function mySubmit()
  {
   somethingWrong=false
   if(form1.ComponentSelect.selectedIndex==0)
     {
       alert("You must choose a Component")
       somethingWrong=true
     }
  if(form1.LawSelect.selectedIndex==0)
    {
     alert("You must choose a Law")
     somethingWrong=true
     }
   if (!somethingWrong)
    {
     alert("LawNo selected =" + form1.LawSelect.selectedIndex + " and component selected is " + form1.ComponentSelect.selectedIndex)
     astring="http://pertinax.cms.shu.ac.uk/mmtec/mm32/HughInputAQuestion2.asp?LawNo=" + form1.LawSelect.selectedIndex+"&ComponentNo=" + form1.ComponentSelect.selectedIndex
     alert("Am calling " + astring)
     form1.action= astring
    }
  }

  function ComponentChanged()
  {
   if(form1.ComponentSelect.selectedIndex==0) { alert("You must choose a Component") }
   else
    {
     document.all.Submit.style.visibility='visible'
    }
  }
</SCRIPT>
</head>

<body>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
   HaveChosen=False
   Set MyConn=Server.CreateObject("ADODB.Connection")
   Set Rs=Server.CreateObject("ADODB.RecordSet")
   Set Rs2=Server.CreateObject("ADODB.RecordSet")
   MyConn.Open("mm32")
   Rs.Open "SELECT * From Law ORDER by lawNo", MyConn, 1, 2
   LawChosen=Request.Form("LawSelect")
   If Not IsNull(LawChosen) Then
    LawChosen=Cint(LawChosen)
    SQLString="SELECT * From Component WHERE lawNo=" & LawChosen
    Rs2.Open SQLString, MyConn, 1, 2
    HaveChosen=True
   End If


  Response.write("")
  Response.write("<P>")
  Response.write("<P>")
  Response.write("First Select a Law<P>")
  Response.write("<form name='form1' method='post' >")

  Response.write("<SELECT Name='LawSelect' SINGLE size=10 onChange='lawChanged()'> ")
  Response.write("<OPTION Value='NONE'>--Choose a Law--")

    While NOT Rs.EOF
      astring="<OPTION VALUE=" & Rs("lawNo")
    If Rs("lawNo") = LawChosen Then
       astring=astring & " SELECTED"
      End if
     Response.write(astring & ">" & Rs("lawNo") & ". " & Rs("lawText"))
     Rs.MoveNext
    WEND

  Response.write("</SELECT>")
  If HaveChosen Then
    Response.write("<SELECT Name='ComponentSelect' SINGLE size=10 onChange='ComponentChanged()' > ")
    Response.write("<OPTION Value='NONE'>--Choose a Component--")
     While NOT Rs2.EOF
      astring="<OPTION VALUE=" & Rs2("componentNo") & ">" & Rs2("componentNo") & ". " & Mid(Rs2("componentText"),1,30)
      Response.write( astring & "<BR>")
      Rs2.MoveNext
     WEND
    Response.write("</SELECT>")
 End If



   Response.write("<p>")
   Response.write(" <input type='submit' name='Submit' value='Submit' onClick='mySubmit()' STYLE='visibility:hidden'>")
   Response.write("</p>")
  Response.write("</form>")
  Response.write("<p><strong></strong> </p>")
%>
</body>
</html>


andrew
 
Old August 16th, 2003, 11:09 PM
Registered User
 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tcasp
Default

Andrew:

            I tried your code by making changes but it does not work according to my objective, that is populate the first box and then second one according to selected category from first one,then choose the category item from second one and display the information on the second page about the selected item from the database.

if you want to c me code then I can post it here,I have to finish this as early as possible.

I will appreciate your help.Thank u.

also what is purpose of using 1,2 in here;Rs.Open "SELECT * From Law ORDER by lawNo", MyConn, 1, 2.









Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Boxes tjs206 VB Databases Basics 2 December 10th, 2003 05:20 PM
Combo Boxes tjs206 VS.NET 2002/2003 7 November 7th, 2003 04:45 PM
combo boxes damnnono_86 Access 2 October 15th, 2003 09:00 PM
Combo Boxes Louisa Beginning VB 6 2 September 10th, 2003 09:26 AM





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