Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Selezione in una combo

  1. #1

    Selezione in una combo

    Caio a tutti .... ho una pagina con una combo dove vorrei che una volta effettuata la selezione e ricaricata la pagina(il form punta alla stessa pagina ) mi rimanesse selezionata la voce della combo scelta ..... in realtà si seleziona sempre la prima voce della combo

    STO DIVENTANDO MATTO ... grazie in anticipo a tutti

    <select name="Sezione" class="testo" id="Sezione" onchange="submit()">
    <option value="0" <% if Sezione=0 then %> selected <% end if %>>SELEZIONARE UNA SEZIONE</option>
    <% dim RstComboSezione
    Sql = "SELECT * FROM sezione"
    Set RstComboSezione = Server.CreateObject("ADODB.Recordset")
    RstComboSezione.Open Sql ,ConnectDb
    do until RstComboSezione.eof %>
    <option value="<%= RstComboSezione("IDSEZIONE") %>" <% if RstComboSezione("IDSEZIONE")=Sezione then %> selected <% end if %>><%= RstComboSezione("SEZIONE") %></option>
    RstComboSezione.movenext
    loop
    RstComboSezione.close
    set RstComboSezione = nothing %>
    </select>

  2. #2
    La questione è stata dibattuta milioni di volte, l'ultima qui:

    http://forum.html.it/forum/showthrea...hreadid=704021

    e qui

    http://forum.html.it/forum/showthrea...hreadid=705080

    un esempio funzionante è qui

    http://www.larianaweb.com/utilities_...he/054_teo.asp

    il suo codice è questo

    codice:
    <html><head>
    <title>Esempio - Select dinamiche</title>
    <script language="javascript" type = "text/javascript">
    
    function vai(){
    var test;
    test="true";
     	
    	if (test=="true")
    				{
    				document.form.action="pagina.asp";
    				document.form.submit();
    				}
    	}
    
    </script>
    </head>
    
    
    <body>
    <%
    reg = request.querystring("regioni")
    prov = request.querystring("capoluogo")
    com = request.querystring("comuni")
    
    %>
    <hr> 
    
    
    <form name="form">
    <div align="center">
      <center>
      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1">
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td align="left">
          <p style="margin-left: 5; margin-right: 5">
          <font face="Verdana" size="1">Selezionare REGIONE</font></td>
          <td></td>
          <td> 
    <select size="1" name="REGIONI" style="font-size: 8 pt; font-family: Verdana" onChange="submit(this);">
                    <option value="0" selected>------TUTTI------</option>
    <%             
    
    'FACCIO POPOLARE LA PRIMA SELECT              
    sql = "SELECT * FROM REGIONI ORDER BY REGIONI desc"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, cn, 3, 3
    
    Do While Not rs.EOF
    Dim strVAR
    strVAR = rs("ID_REGIONI")
    
    %>
    
    <option	value="<%=RS.Fields.Item("id_regioni").Value%>"
    <% 	if reg = cstr(strVar) then response.write("selected") end if%>>
    <%= RS.Fields.Item("REGIONI").Value%></option>	
    				
    
    <%
    rs.MoveNext
    Loop
    rs.Close
    set rs = Nothing
    %>
    
                  </select></td>
        </tr>
        <tr>
          <td align="left">
          <p style="margin-left: 5; margin-right: 5"></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td align="left">
          <p style="margin-left: 5; margin-right: 5">
          <font face="Verdana" size="1">Selezionare CAPOLUOGO</font></td>
          <td></td>
          <td>
                  
    <select size="1" name="CAPOLUOGO" style="font-size: 8 pt; font-family: Verdana" onChange="submit(this);">
    
                    <option value="0" selected>------TUTTE------</option>
                    <%
    
    'FACCIO POPOLARE LA SECONDA SELECT 
    'SE IL VALORE DI VARIABILE E' DIVERSO DA TUTTI
    if cint(reg) > 0  Then
    
    sql1 = "select distinct TABELLA.id_CAPOLUOGO as codice, CAPOLUOGO.CAPOLUOGO as provincia from TABELLA inner join CAPOLUOGO on TABELLA.id_CAPOLUOGO = CAPOLUOGO.id_CAPOLUOGO WHERE TABELLA.id_REGIONI = "&reg&" "
    Set rs1 = Server.CreateObject("ADODB.Recordset")
    rs1.Open sql1, cn, 3, 3
    
    Do While Not rs1.EOF
    dim strCap
    strCAP = rs1("codice")
    %>
    <option	value="<%=RS1("codice")%>" 
    <%if prov = cstr(strCAP) then response.write("selected") end if%>>
    <%=RS1("provincia")%>
    </option>
    <%
    rs1.MoveNext
    Loop
    rs1.Close
    set rs1 = Nothing
    
    'ALTRIMENTI SE IL VALORE DI VARIABILE E' TUTTI
    else 
    
    sql2 = "SELECT ID_CAPOLUOGO, CAPOLUOGO FROM CAPOLUOGO order BY CAPOLUOGO asc"
    'response.write(sql2):response.end
    Set RS2 = Server.CreateObject("ADODB.Recordset")
    
    rs2.open sql2, cn, 3, 3
    
    Do While Not rs2.EOF
    
    %>
    
    <option	value="<%=RS2.Fields.Item("id_CAPOLUOGO").Value%>"
    <%if prov = cstr(RS2.Fields.Item("id_CAPOLUOGO").Value) then response.write("selected") end if%>><%= RS2.Fields.Item("CAPOLUOGO").Value%></option>	
    			                
    <%
    RS2.Movenext
    LooP
    rs2.close 
    set rs2 = nothing 
    end if
    
    %>
    </select></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>
          <p style="margin-left: 5; margin-right: 5">
          <font face="Verdana" size="1">Selezionare COMUNE</font></td>
          <td></td>
          <td>
          <font face="Tahoma">
    <select size="1" name="COMUNI" style="font-size: 8 pt; font-family: Verdana">
                    <option value="TUTTI">------TUTTE------</option>
    
    <%
                    
    'FACCIO POPOLARE LA TERZA SELECT 
    
    sql3 = "select distinct comune from tabella WHERE 1=1 "               
    
    
    
    if prov > 0 then  'se è stata scelta una provincia
    
    	sql3 = sql3&" AND id_capoluogo = "&prov&""
    	
    else
    
    	if reg > 0 then  ' se è stata scelta una regione
    	
    	sql3 = sql3&" AND id_regioni = "&reg&""
    
    	end if
    end if	
    
    
    sql3 = sql3&" order by  comune asc"
    
    	Set rs3 = Server.CreateObject("ADODB.Recordset")
    	rs3.Open sql3, cn, 3, 3
    
    	Do While Not rs3.EOF%>
    
    %>
    
    	<option	value="<%=replace(rs3("comune"), " ", "_")%>"
     	<%if com = rs3("comune") then response.write("selected") end if%>>
    	<%=rs3("comune")%></option>
    
    <%
    	rs3.MoveNext
    	Loop
    
    %></select><%
    
    rs3.Close
    set rs3 = Nothing
    %>
    </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td>
          <font face="Tahoma">
    <input type="submit" name="Submit" value="Invia Richiesta &gt;&gt;&gt;" style="font-size: 8 pt; font-family:Verdana"></font></td>
          <td></td>
          <td><input type="reset" name="reset" value="Azzera Campi  &gt;&gt;&gt;" style="font-size: 8 pt; font-family: Verdana"/></td>
        </tr>
      </table>
      </center>
    </div>
    
    
      </p>
    </form>
    <%
    
    
    cn.close 
    set cn = nothing 
    %>
    </body> 
    </html>
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  3. #3
    Il trucco è in queste righe:

    codice:
    <option	value="<%=RS.Fields.Item("id_regioni").Value%>"
    <% 	if reg = cstr(strVar) then response.write("selected") end if%>>
    <%= RS.Fields.Item("REGIONI").Value%></option>
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  4. #4
    Amen
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

  5. #5
    Gli Id sedde due combo vengono passati senza alcun problema quando viene ricaricata la pagina, il mio problema è che non riesco e far rimaner selezionato la scelta effettuata nella combo box una volta ricaricata la pagina nonostante confronto l'id del corrente record con l'id passato nel loop

  6. #6
    Risolto grazie era per colpa di due valori che non venivano confrontati correttamente .... uno era numerico (quello del bd) ...l'altro stringa(quello della combo).....grazie comunque

  7. #7
    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.