Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    Select con selected corretto

    Cosa c'è di sbagliato in questo codice? Io vorrei che caricato un form contenente questa select, essa assuma il valore recuperato da un db.
    Ovvero se nel DB il campo tipodocumento è uguale a C, la terza opzione dovrà essere quella selezionata.

    <select name="valore">
    <option value="a" <%if rs.fields("tipodocumento")="a" then: Response.Write("selected"): end if%>>a</option>
    <option value="b" <%if rs.fields("tipodocumento")="b" then: Response.Write("selected"): end if%>>b</option>
    <option value="c" <%if rs.fields("tipodocumento")="c" then: Response.Write("selected"): end if%>>c</option>
    </select>

  2. #2
    qual è il codice html che ti restituisce?
    Mr. Fepreto Nirra
    (I've been the wild rover for many of years - Spent all my money on whiskey and beer)
    E' PROPRIO UN BEL LOCALINO, BOB!
    ... ma non è il bicchiere giusto ...

  3. #3
    Nell'html non compare nessun Selected ma il campo rs.fields("tipodocumento") viene valorizzato correttamente.

  4. #4
    codice:
     <select name="valore">
    <option value="a" <%if rs.fields("tipodocumento")="a" then%> selected="selected" <% end if%>>a</option>
    <option value="b" <%if rs.fields("tipodocumento")="b" then%> selected="selected" <% end if%>>b</option>
    <option value="c" <%if rs.fields("tipodocumento")="c" then%> selected="selected" <% end if%>>c</option>
    </select>
    meglio ancora sarebbe

    codice:
    'la varibile che leggi e che devi andare a controllare
    tipodoc=request.item("tipodoc")
    
    %><select name="tuaselect"> <%
    
    do while not rs.eof
     tipodocumento=rs.fields("tipodocumento")
     
     if tipodoc=tipodocumento then
     'se il controllo è verificato setto la option come selected
      %>
      <option value="<%=tipodocumento%>" selected="selected" ><%=tipodocumento%></option>
      <%
     else
     'se il controllo non è verificato
      %>
      <option value="<%=tipodocumento%>" selected="selected" ><%=tipodocumento%></option>
      <%
     ens if
    
     rs.movenext
    loop
    %></select> <%

    ciao

  5. #5
    puo anche essere che ci voglia uno spazio prima del selected, o dopo
    prova e facce sapè
    Mr. Fepreto Nirra
    (I've been the wild rover for many of years - Spent all my money on whiskey and beer)
    E' PROPRIO UN BEL LOCALINO, BOB!
    ... ma non è il bicchiere giusto ...

  6. #6
    Niente. Ho provato sia con la Prima soluzione di occhio crepato, e sia mettendo spazi prima e dopo la Selected ma tutto come prima.
    Sinceramente non capisco il perchè. Mi sembra che dovrebbe andare, errori non ne vedo...

  7. #7
    1- il campo rs.fields("tipodocumento") lo leggi all'interno di un ciclo?
    2- la select, intesa come tag <select>, la crei fuori dal ciclo?

    posta un po più di codice

  8. #8
    Ecco qua, tieni presente che tutti gli rs.fields vengono valorizzati correttamente compreso
    il rs.fields("tipodocumento").
    Tant'è che se io sostituissi la Select con un Input Text, l'input verrebbe valorizzato correttamente.


    .................
    <%
    set rs = server.createObject("ADODB.recordset")
    sqlstr="SELECT * from ..............."
    rs.Open sqlstr, cn


    %>
    ........

    <body>
    <table>
    <form>
    <tr>
    <td>Tipo Documento </td>
    <td>
    <select name="tipodocumento">
    <option value="email" <%if rs.fields("tipodocumento")="email" then%> selected="selected" <% end if%>>email</option>
    <option value="cartaceo" <%if rs.fields("tipodocumento")="cartaceo" then%> selected="selected" <% end if%>>cartaceo</option>
    <option value="fax" <%if rs.fields("tipodocumento")="fax" then%> selected="selected" <% end if%>>fax</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>Mittente</td>
    <td><input type="text" name="mittente" value="<%=rs.fields("mittente")%>"></td>
    </tr>
    <tr>
    <td valign="top" class="ip_zona">Oggetto</td>
    <td><textarea name="oggetto" rows="2" class="tx_small"><%=rs.fields("oggetto")%></textarea></td>
    </tr>
    <tr>
    <td valign="top" class="ip_zona">Note</td>
    <td><textarea name="Note" rows="2" class="tx_small"><%=rs.fields("Note")%></textarea></td>
    </tr>
    <tr>
    <td colspan="2">
    <div align="right">
    <input type="submit" value="invia">
    </div></td>
    </form>
    </tr>
    </table>
    </body>
    </html>

  9. #9

    prova
    codice:
    <select name="tipodocumento">
    <option value="email" <%if LCase(rs.fields("tipodocumento"))=LCase("email") then%> selected="selected" <% end if%>>email</option>
    <option value="cartaceo" <%if LCase(rs.fields("tipodocumento"))=LCase("cartaceo") then%> selected="selected" <% end if%>>cartaceo</option>
    <option value="fax" <%if LCase(rs.fields("tipodocumento"))=LCase(rs.fields("tipodocumento")="fax") then%> selected="selected" <% end if%>>fax</option>
    </select>

    ps usa il tag [ code ] per mettere il codice altrimenti si fa fatica a leggere

  10. #10
    sei assolutamente certo che il campo nel db sia identico, ribadisco IDENTICO, ai valori con cui lo confronti?

    Io una volta ho sbattuto la testa contro il muro un bel po' prima di scoprire che nel campo avevo "a"+chr(13) e lo confrontavo con "a"...

    Naturalmente è solo un esempio, ci potrebbero assere altri caratteri invisibili, come lo spazio, la tabulazione...

    puoi anche provare ad usare substr per prendere solo il primo carattere del valore del campo!

    Ciao!
    "Le uniche cose che sbagli sono quelle che non provi a fare."
    Atipica

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.