www.webdeveloper.com
Results 1 to 4 of 4

Thread: 2 dropdown lists populated by db

  1. #1
    Join Date
    Apr 2006
    Posts
    52

    2 dropdown lists populated by db

    Hi,
    I have 2 tables..both linked with EMP_REF(key)

    Table1 (fields) - EMP_REF,EMPNAME
    Table2 (fields) - EMP_REF,CPD_DATE
    I would like to be able to fill dropdown list 1 from table1 with EMPNAME. whatever is selected from dropdown list 1, dropdown list 2 is filled dynamically with CPD_DATE from table2.

    Whats the easist way to achive this..?

    thanks
    CJ.

  2. #2
    Join Date
    Dec 2004
    Location
    Eau Claire, WI
    Posts
    153
    I believe that you need to integrate Javascript into the equation to make this happen.

    Here's one example...
    http://www.javascriptkit.com/script/cut183.shtml

    I have also heard mention that this is easier to accomplish with ASP.NET.. I can't really verify that though..
    Brad Candell - Owner/Developer
    http://www.EauClaireWEB.com - Web Development

  3. #3
    Join Date
    Apr 2006
    Posts
    52
    hi, I have tried to follow this example .. and so far I have the following

    [HTML]
    Code:
    ' Populate 1st Dropdown list with EMPLOYEE NAME
    	Set oRs = oConn.Execute(strSQL, lngRecs, 1) %>
    </font> 
    <form action="test.asp" method="post" >
      <font face="Verdana, Arial, Helvetica, sans-serif"><i>Select Employee Name <font face="Arial" size="2"> 
      <%
       Ors.movefirst
    ' Get EMPLOY_REF for first row
       EmpRefone = ors.fields("EMPLOY_REF")
      %>
       <select size=1 name="stage1" onChange="redirect(this.options.selectedIndex)">
       <%Do While Not ors.EOF%>
    			    <option value="<%= ors.fields("EMPLOY_REF")%>"><%=ors.fields("name")%></option>
    <%
     				ors.movenext
    	Loop
    	%></select><%
    	set ors = nothing
    %>
    	<select name="stage2" size="1">
    <%	
    	strsql = "Select cpd_No,intdate from CPD where emp_ref = '" & EmpRefone & "'"
    	Set ors2= oconn2.execute(strsql,lngrecs,1)
    	Do While not ors2.eof	
    %>
    		<option value="<%=ors2.fields("CPD_NO")%>"><%=ors2.fields("intdate")%></option>
    <%
    		ors2.movenext
    	Loop
    	set ors2 = Nothing	
    %>
    </select> 
      <input type="submit" name="Submit" value="Next Page">
    </form>
    I think the HTML looks ok, but I have NO IDEA how to pass the database information to the javascript (below). ie, no of rows, intdate.. inorder to make it dynamic and populate the 2nd list box with databse information.

    need help please?


    [SCRIPT]

    Code:
    var groups=document.doublecombo.example.options.length
    var group=new Array(groups)
    for (i=0; i<groups; i++)
    group[i]=new Array()
    
    group[0][0]=new Option("JavaScript Kit","http://javascriptkit.com")
    group[0][1]=new Option("News.com","http://www.news.com")
    group[0][2]=new Option("Wired News","http://www.wired.com")
    
    group[1][0]=new Option("CNN","http://www.cnn.com")
    group[1][1]=new Option("ABC News","http://www.abcnews.com")
    
    group[2][0]=new Option("Hotbot","http://www.hotbot.com")
    group[2][1]=new Option("Infoseek","http://www.infoseek.com")
    group[2][2]=new Option("Excite","http://www.excite.com")
    group[2][3]=new Option("Lycos","http://www.lycos.com")
    
    var temp=document.doublecombo.stage2
    
    function redirect(x){
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){
    temp.options[i]=new Option(group[x][i].text,group[x][i].value)
    }
    temp.options[0].selected=true
    }
    
    function go(){
    location=temp.options[temp.selectedIndex].value
    }
    //-->
    </script>

  4. #4
    Join Date
    Apr 2006
    Posts
    52
    Anybody help with this?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles