#1
  1. Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Oct 2009
    Location
    INDONESIA
    Posts
    107
    Rep Power
    9

    How to keep the last selected value selected after On change for 2 dynamic dropdown


    I am making a simple web app that has 2 drop down list, in the first dropdown after i selected, On the onchange I have made call to create a querystring through JS function of the selected Index to query information and show in second dropdown. This Code Running well.

    BUT

    value in first dropdown Not showing the last selected value after On change.

    How to keep the last selected value in first dropdown selected after On change ??.

    this is my last code :

    Code:
    <html>
    <head>
    <title></title>
    
    <script type="text/javascript">
    function populateTheSecondDropdown(valueToUse)
    {
    window.location.href="report_atas.asp?value=" + valueToUse + "&action=loadcombo2";
    }
    </script>
    
    </head>
    <body>
    <form action="report_bawah.asp" target="report_bawah" name="qc" id="qc" method="post" onSubmit="return verifikasi_report_atas()">
    <table cellpadding="1" cellspacing="1" border="0">
    	<tr>
    		<td valign="baseline">Nama TL</td>
    		<td width="15" align="center" valign="baseline">:</td>		
    		<td valign="baseline">
    <%
    
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open s96
    Set rs=conn.execute("SELECT DISTINCT TL,TL_ACD FROM NAMAPEG ORDER BY TL")
    
    %>		
    		
    		<select class="bodystyle" name="nama_tl" id="nama_tl" style="width:120px" onchange='populateTheSecondDropdown(this.options[this.selectedIndex].value)'>
    
    <%
    		DO WHILE NOT rs.eof
    %>
    		<option value='<%=rs.fields("TL_ACD")%>'><%=rs.fields("TL")%></option>
    <%
    		rs.movenext
    		loop
    %>				
    		</select>
    		
    		</td>
    				
    		<td width="20" valign="baseline">&nbsp;</td>
    		<td valign="baseline">Nama Agent</td>
    		<td width="15" align="center" valign="baseline">:</td>
    		<td valign="baseline">		
    		
    <%
    	
    action=request.querystring("action")
    
    if action ="loadcombo2" then
    propval=request.querystring("value")
    
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open s96
    Set rs2 =conn.execute("Select distinct NAMA from NAMAPEG where TL_ACD='" & propval &"' order by NAMA")
    
    else
    
    Set rs2 =conn.execute("Select distinct NAMA from NAMAPEG order by NAMA")
    
    end if
    	
    %>
    
    		<select name="nama_agent" class="bodystyle" style="width:180px">
    <%
    
        	DO WHILE NOT rs2.eof
    %>
    		<option value='<%=rs2.fields("NAMA")%>'><%=rs2.fields("NAMA")%></option>
    <%
    		rs2.movenext
    		loop
    		
    %>				
    		
    		</select>




    [/code]
  2. #2
  3. KIS
    ASP Hero (2000 - 2499 posts)

    Join Date
    Jul 2007
    Location
    USA
    Posts
    2,099
    Rep Power
    1438
    Code:
    <%
    
    Set conn = Server.CreateObject("ADODB.Connection")
    
    conn.open s96
    Set rs=conn.execute("SELECT DISTINCT TL,TL_ACD FROM NAMAPEG ORDER BY TL")
    
    action=request.querystring("action")
    propval=request.querystring("value")
    
    %>		
    		
    		<select class="bodystyle" name="nama_tl" id="nama_tl" style="width:120px" onchange='populateTheSecondDropdown(this.options[this.selectedIndex].value)'>
    
    <%
    		DO WHILE NOT rs.eof
    %>
    		<option value='<%=rs.fields("TL_ACD")%>' <%If propval=rs.fields("TL_ACD") Then response.write "selected"%>><%=rs.fields("TL")%></option>
    <%
    		rs.movenext
    		loop
    %>				
    		</select>

    Comments on this post

    • html807 agrees : agree with u
    Please give respect to those that helped solve an issue by clicking on the reputation icon
  4. #3
  5. Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Oct 2009
    Location
    INDONESIA
    Posts
    107
    Rep Power
    9

    solved by keep it simple


    Originally Posted by keep_it_simple
    Code:
    <%
    
    Set conn = Server.CreateObject("ADODB.Connection")
    
    conn.open s96
    Set rs=conn.execute("SELECT DISTINCT TL,TL_ACD FROM NAMAPEG ORDER BY TL")
    
    action=request.querystring("action")
    propval=request.querystring("value")
    
    %>		
    		
    		<select class="bodystyle" name="nama_tl" id="nama_tl" style="width:120px" onchange='populateTheSecondDropdown(this.options[this.selectedIndex].value)'>
    
    <%
    		DO WHILE NOT rs.eof
    %>
    		<option value='<%=rs.fields("TL_ACD")%>' <%If propval=rs.fields("TL_ACD") Then response.write "selected"%>><%=rs.fields("TL")%></option>
    <%
    		rs.movenext
    		loop
    %>				
    		</select>

    yeah its work ....
    thanks to you ....

Similar Threads

  1. Replies: 11
    Last Post: September 24th, 2006, 03:32 PM
  2. Getting the selected value from a dropdown
    By Trondhardt in forum ASP Development
    Replies: 6
    Last Post: August 18th, 2006, 05:47 AM
  3. Validation
    By princecharles in forum HTML, JavaScript And CSS Help
    Replies: 1
    Last Post: February 13th, 2006, 10:20 AM
  4. Show and hide fields with dynamic dropdown select box
    By geckodeep in forum ASP Development
    Replies: 12
    Last Post: September 16th, 2003, 09:54 AM

IMN logo majestic logo threadwatch logo seochat tools logo