Populate Pull down menu from access database on selection of previous pull down menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • giandeo
    New Member
    • Jan 2008
    • 46

    Populate Pull down menu from access database on selection of previous pull down menu

    Hello Experts.
    Could you find a solution for this problem please!

    I have the following tables in Access Database

    Table Name: origin
    Fields Names: country, countrycode

    Table Name: make
    Fields Names: countrycode, make


    Table Name: toyota
    Fields Name: model

    Table Name: nissan
    Fields Name: model

    Table Name: mazda
    Fields Name: model


    I want to design a form in ASP where users can choose the specification of his car from a series of pull down menus.


    There are 4 Pull down menus/Combo boxes as follows:

    Combo box 1: Origin [populates data from table origin]

    Combo box 2: Make [populates data from table make]
    Initially disabled. Once an element is selected in combo box 1, combo box 2 is enabled and is populated with data corresponding to that item from table make.

    Combo box 3: Model [populate data from a table chosen from the list specified in combo box 2]
    Initially disabled. Once an element is selected in combo box 2, combo box 3 is enabled and is populated with data corresponding to that item. For example, if a user select Toyota in combo box 2, then combo box 3 is automatically populated with data from table Toyota that is, Corolla, Vitz, Allion, Corona etc..


    Combo box 4: Capacity [populate data from a table chosen from the list specified in combo box 3]
    Initially disabled. Once an element is selected in combo box 3, combo box 4 is enabled and is populated with data corresponding to that item.


    I have given it a try
    Here are my codes

    Code:
    <%@ Language = VBscript %>
    <% Option Explicit %>
    <% Response.Buffer = True %>
    
    <html>
    <head>
    <title>Search Your Car</title>
    <SCRIPT language=JavaScript>
    function reload(form){
    var strval=form.make.options[form.make.options.selectedIndex].value;
    self.location='car.asp?make=' +str val ;
    }
    </script>
    
    <SCRIPT language=JavaScript>
    function reload(form1){
    var strval1=form1.make.options[form1.make.options.selectedIndex].value;
    self.location='car.asp?make=' + strval1 ;
    }
    </script>
    
    </head><body>
    
    <%
    Dim objconn,objRS,strSQL,make
    make=Request.QueryString("make")
    Set objconn = Server.CreateObject("ADODB.Connection")
    objconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("yeshti.mdb")
    objconn.Open
    
    Set objRs = Server.CreateObject("ADODB.Recordset")
    
    ‘The First drop down Menu/Combo Box'
    
    strSQL = "SELECT * from origin"
    objRS.Open strSQL, objconn
    Response.Write "<form method=post name=f1 action=''><select name=country onchange='reload(this.form)'><option value=''>Select origin</option>"
    Do While Not objRS.EOF 
    	Response.Write "<option value=" & objRs("country") & ">" & objRs("country") & "</option>"
         objRS.MoveNext
     Loop
    objRs.Close
    Response.Write "</select>"
    Response.Write "<br>----<br>"
    
    
    ‘ Second drop down menu
    
    If len(country) > 1 Then
    
    strSQL = "SELECT  * FROM make where countrycode='" & countrycode &"'"
    objRS.Open strSQL, objconn
    Response.Write "<select name=make onchange='reload(this.form1)'><option value=''>Select origin</option>"
    Do While Not objRS.EOF 
    	Response.Write  objRs("make") & "<br>"
         objRS.MoveNext
     Loop
    Response.Write "</Select>"
    objRs.Close
    
    objconn.Close
    end if 
    
         %>
    </body>
    </html>
    Sir, I am stuck. I do not know how to proceed. I really need your help!
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    hi giandeo,
    first of all have you any experience regarding AJAX.if yes then i can give you a more managed way to do it and more efficient too,apart from if you know javascript , its same like it
    regards,
    omer

    Comment

    • giandeo
      New Member
      • Jan 2008
      • 46

      #3
      Originally posted by omerbutt
      hi giandeo,
      first of all have you any experience regarding AJAX.if yes then i can give you a more managed way to do it and more efficient too,apart from if you know javascript , its same like it
      regards,
      omer
      No sir, I do not know AJAX, I am new to programming. I am learning ASP and Javascript.

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        Originally posted by giandeo
        No sir, I do not know AJAX, I am new to programming. I am learning ASP and Javascript.
        its a good practice to start your javascript in ajax its same as javascript here
        http://www.w3schools.com/ajax/ajax_intro.asp just have an over view it would open a new era of solutions to your problems,come back when you have gone through these pages then i tell you how to make that work with your code and you will be amazed to see such efficient and accurate results, don worry thats for just to have an idea that what AJAX is actually :)
        regards,
        omer

        Comment

        • giandeo
          New Member
          • Jan 2008
          • 46

          #5
          Originally posted by omerbutt
          its a good practice to start your javascript in ajax its same as javascript here
          http://www.w3schools.com/ajax/ajax_intro.asp just have an over view it would open a new era of solutions to your problems,come back when you have gone through these pages then i tell you how to make that work with your code and you will be amazed to see such efficient and accurate results, don worry thats for just to have an idea that what AJAX is actually :)
          regards,
          omer
          Thank you so much for your suggestions Sir. I am going to have a look about how AJAX works and will soon report to you.

          Comment

          • omerbutt
            Contributor
            • Nov 2006
            • 638

            #6
            Originally posted by giandeo
            Thank you so much for your suggestions Sir. I am going to have a look about how AJAX works and will soon report to you.
            :) any time giandeo, feel free to ask
            regards,
            omer.

            Comment

            Working...