Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Impostare SELECTED in un fomr con dinamic option

    Ciao,

    in un form ho qsto codice per selezionare un campo:

    Codice PHP:
    <select name="ID_particella_sede_fornitura">
    <
    option value="ID_particella_sede_fornitura">Seleziona Particella</option>
    <% 
    SQL"SELECT * FROM TBL_TOPONIMI"
    Set RSTOPONIMI Server.CreateObject("ADODB.Recordset")
    RSTOPONIMI.Open sqloConn3
    RSTOPONIMI
    .MoveFirst  
    Do While Not RSTOPONIMI.EOF %>
    <
    option value=<%=RSTOPONIMI("ID_Particella")%>><%=RSTOPONIMI("Particella")%></option>
    <%
    RSTOPONIMI.MoveNext
    Loop
    RSTOPONIMI
    .Close
    set RSTOPONIMI 
    Nothing %>
    </
    select
    Qllo che vorrei fare è impostare SELECTED un determinato valore che nel mio caso è RSTOPONIMI("ID_Particella") = "190"

    Ho provato con IF ma non funziona e nn sono nemmeno sicuro che sia la strada giusta.

    La TBL_TOPONIMI contiene decine di valori.


    Grazie dell'aiuto

    JK
    JK
    "meglio un giorno da cinghiale che cento da porchetta"
    http://www.radiobase.net in fase di ristrutturazione... anche se non sembra

  2. #2
    infatti si risolve con una bella IF. fa' vedere la tua prova (quella che dici che non funzica)

  3. #3
    Grazie... e infatti dopo una sigaretta... ho risolto così:



    Codice PHP:
    select name="ID_particella_sede_fornitura"> <option value="ID_particella_sede_fornitura">Seleziona Particella</option> <% SQL"SELECT * FROM TBL_TOPONIMI" Set RSTOPONIMI Server.CreateObject("ADODB.Recordset"RSTOPONIMI.Open sqloConn33  RSTOPONIMI.MoveFirst   Do While Not RSTOPONIMI.EOF %> <option value=<%=RSTOPONIMI("ID_Particella")%>

    <% if 
    RSTOPONIMI("ID_Particella")= "190" then %> selected="selected"<% end if %>>

    <%=
    RSTOPONIMI("Particella")%></option>  <% if optsett valore then %> selected="selected"<% end if %>  <% RSTOPONIMI.MoveNext Loop RSTOPONIMI.Close set RSTOPONIMI Nothing %> </select


    JK
    JK
    "meglio un giorno da cinghiale che cento da porchetta"
    http://www.radiobase.net in fase di ristrutturazione... anche se non sembra

  4. #4
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    non è meglio una funzione ?

    function check_option(x,n)

    if x = n then
    check_option = "selected"
    else
    check_option = ""
    end if

    end function

  5. #5
    Potrebbe anche essere. Per adesso avevo solo 1 controllo da fare e quindi la soluzione che ho trovato è ok, cmq grazie del suggeriemnto. Ne terrò sicuramente conto.

    Thanks

    JK
    JK
    "meglio un giorno da cinghiale che cento da porchetta"
    http://www.radiobase.net in fase di ristrutturazione... anche se non sembra

  6. #6
    mi sembrava strano che tutto fosse ok.

    La qstione adesso è la seguente:

    risposto il codice:

    Codice PHP:
    select name="ID_particella_sede_fornitura">
    <
    option value="ID_particella_sede_fornitura">Seleziona Particella</option
    <% 
    SQL"SELECT * FROM TBL_TOPONIMI" Set RSTOPONIMI Server.CreateObject("ADODB.Recordset"RSTOPONIMI.Open sqloConn33  RSTOPONIMI.MoveFirst   
    Do While Not RSTOPONIMI.EOF %> 
    <
    option value=<%=RSTOPONIMI("ID_Particella")%>
    <% if 
    RSTOPONIMI("ID_Particella")= "190" then %> 
    selected="selected"<% end if %>>
    <%=
    RSTOPONIMI("Particella")%>
    </
    optionselected="selected"<% end if %> 
    <% 
    RSTOPONIMI.MoveNext 
    Loop 
    RSTOPONIMI
    .Close 
    set RSTOPONIMI 
    Nothing %> 
    </
    select
    Qsto mi permette di caricare la mia variabile nel db. E fin qui tutto ok.

    Vorrei però che nella pg "modifica" posso oltre che vedere il valore del db anche di selezionarne un'altro tra le opzioni e andare a sovrascrivere il precedente valore.

    Ho provato con:

    Codice PHP:
    <select name="ID_Rete"> <option value="<% = RSF("ID_Rete")%>">Seleziona Tensione</option>  <% SQL"SELECT * FROM TBL_RETE" Set RSRETE Server.CreateObject("ADODB.Recordset"RSRETE.Open sqloConn33   RSRETE.MoveFirst   Do While Not RSRETE.EOF %> <option value=<% = RSRETE("ID_Rete") %><% IF RSF("ID_Rete") = RSRETE("ID_Rete"then %> selected="selected"<% end if %>><%=RSRETE("Rete")%></option> <% RSRETE.MoveNext Loop RSRETE.Close set RSRETE Nothing %> </select
    cioè cercando di impostare il valore selected su qllo ricavato dal recordset del db. E infatti si vede.

    Il problema è che qlsiasi altra opzione scelgo mi passa sempre lo stesso valore.

    Se nel db ho "xxx" (e lo vedo come prima opzione) e nel form seleziono come opzione "yyy" mi va sempre a scrivere xxx

    Qlche suggerimento?

    JK
    JK
    "meglio un giorno da cinghiale che cento da porchetta"
    http://www.radiobase.net in fase di ristrutturazione... anche se non sembra

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 © 2026 vBulletin Solutions, Inc. All rights reserved.