Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81

    Costrutto If con checkbox

    Salve a tutti.
    Qualcuno può spiegarmi come fare in modo che in un costrutto If... Then... Else... possa inserire un checkbox che deve scrivere in db un valore se cliccato. il checkbox deve comparire soltanto nel caso in cui la Condizione dell'If sia vera.
    in parole povere, come faccio a integrare If e <input> del listato seguente:

    <% If (rs_utenti.Fields.Item("box").Value) = "1" Then Response.Write "yes"
    Else Response.Write "no"
    End If%>


    <input type="checkbox" name="scatola" value="<%=(rs_utenti.Fields.Item("scatola").Value) %>">

    Grazie

  2. #2
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81
    voglio fare una cosa di questo tipo:
    interrogo il db e se un valore del db è 1, nel mio caso il campo box , allora mi deve comparire un checkbox per inserire un nuovo valore al db, nel mio caso il campo scatola .
    Ditemi se sono stato chiaro

  4. #4
    Utente di HTML.it L'avatar di wallrider
    Registrato dal
    Apr 2003
    Messaggi
    2,755
    ma yes te lo scrive?
    RIP Cicciobenzina 9/11/2010

    "Riseminaciceli, i ceci nell'orto"

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81
    si, lo scrive ma era un controllo per verificare il funzionamento. ora voglio che al posto di "yes" mi dia attivo il checkbox seguente
    <input type="checkbox" name="scatola" value="<%=(rs_utenti.Fields.Item("scatola").Value) %>">
    perchè con questo inserisco un nuovo valore al db

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81
    ho provato a scrivere questo
    <%
    If (rs_utenti.Fields.Item("box").Value) = "1" Then
    Response.Write ("<input type='checkbox' name='scatola' value='" & rs_utenti.Fields.Item("scatola").Value & ">")
    End if
    %>
    ma come risultato mi stampa a video
    <input type='checkbox' name='scatola' value='0>
    cioè mi da il valore nel db (0 oppure 1) del campo scatola.
    ho sbagliato la sintassi?

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81
    nel caso in cui il valore di box è 1 allora devo poter vedere il checkbox scatola, e in quel caso poter inserire il valore checked=1 di scatola nel db
    altrimenti non voglio vedere il checkbox scatola

    Questo è il codice che mi consente di inserire il valore checked (=1) nel db:

    <input <%If (CStr((rs_utenti.Fields.Item("scatola").Value)) = CStr("1")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="scatola" type="checkbox" value="1">

    è questo il codice che la pagina deve attivare se box=1

    Inserisco anche tutto il codice della pagina (premetto che è stata creata con dreamweaver ):
    <%@LANGUAGE="VBSCRIPT"%>

    <%
    Dim MM_editAction
    MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
    If (Request.QueryString <> "") Then
    MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
    End If

    ' boolean to abort record edit
    Dim MM_abortEdit
    MM_abortEdit = false
    %>
    <%
    ' IIf implementation
    Function MM_IIf(condition, ifTrue, ifFalse)
    If condition = "" Then
    MM_IIf = ifFalse
    Else
    MM_IIf = ifTrue
    End If
    End Function
    %>
    <%
    If (CStr(Request("MM_update")) = "form_utente") Then
    If (Not MM_abortEdit) Then
    ' execute the update
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_conn_utenti_STRING
    MM_editCmd.CommandText = "UPDATE tab_utenti SET username = ?, password = ?, nome = ?, cognome = ?, email = ?, box = ?, scatola = ? WHERE id = ?"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 50, Request.Form("username")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 50, Request.Form("password")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 50, Request.Form("nome")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202, 1, 50, Request.Form("cognome")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 50, Request.Form("email")) ' adVarWChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, 1, MM_IIF(Request.Form("box"), 1, 0)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, 1, MM_IIF(Request.Form("scatola"), 1, 0)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "benvenuto.asp"
    If (Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
    MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
    MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
    End If
    Response.Redirect(MM_editRedirectUrl)
    End If
    End If
    %>
    <%
    Dim rs_utenti__MMColParam
    rs_utenti__MMColParam = "1"
    If (Session("MM_username") <> "") Then
    rs_utenti__MMColParam = Session("MM_username")
    End If
    %>
    <%
    Dim rs_utenti
    Dim rs_utenti_cmd
    Dim rs_utenti_numRows

    Set rs_utenti_cmd = Server.CreateObject ("ADODB.Command")
    rs_utenti_cmd.ActiveConnection = MM_conn_utenti_STRING
    rs_utenti_cmd.CommandText = "SELECT * FROM tab_utenti WHERE username = ?"
    rs_utenti_cmd.Prepared = true
    rs_utenti_cmd.Parameters.Append rs_utenti_cmd.CreateParameter("param1", 200, 1, 50, rs_utenti__MMColParam) ' adVarChar

    Set rs_utenti = rs_utenti_cmd.Execute
    rs_utenti_numRows = 0
    %>
    <html>
    <head>
    <title>Modifica dei dati dell'utente</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <form name="form_utente" method="POST" action="<%=MM_editAction%>">



    <input type="text" name="username" value="<%=(rs_utenti.Fields.Item("username").Value )%>">
    username</p>



    <input type="text" name="password" value="<%=(rs_utenti.Fields.Item("password").Value )%>">
    password</p>



    <input type="text" name="nome" value="<%=(rs_utenti.Fields.Item("nome").Value)%>" >
    nome </p>



    <input type="text" name="cognome" value="<%=(rs_utenti.Fields.Item("cognome").Value) %>">
    cognome</p>




    <input type="text" name="email" value="<%=(rs_utenti.Fields.Item("email").Value)%> ">
    email</p>


    <%=(rs_utenti.Fields.Item("sesso").Value)%>

    <input <%If (CStr((rs_utenti.Fields.Item("sesso").Value)) = CStr("True")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="sesso" type="checkbox" id="sesso" value="On">
    sesso</p>



    <input <%If (CStr((rs_utenti.Fields.Item("box").Value)) = CStr("1")) Then Response.Write("checked=""checked""") : Response.Write("checked=""""")%> name="box" type="checkbox" id="box" value="<%=(rs_utenti.Fields.Item("box").Value)%>">
    box


    <% If (rs_utenti.Fields.Item("box").Value) = "1" Then
    Response.Write "yes"
    Else Response.Write "no"
    End If%>
    </p>
    sempre visibile per prova
    <input <%If (CStr((rs_utenti.Fields.Item("scatola").Value)) = CStr("1")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="scatola" type="checkbox" value="1">
    <%=(rs_utenti.Fields.Item("scatola").Value)%>



    <input type="submit" name="Submit" value="Aggiorna i dati">
    </p>
    <input type="hidden" name="MM_update" value="form_utente">
    <input type="hidden" name="MM_recordId" value="<%= rs_utenti.Fields.Item("id").Value %>">
    </form>
    </body>
    </html>
    <%
    rs_utenti.Close()
    %>

  8. #8
    forse così?

    <%
    If (rs_utenti("box").Value) = "1" Then %>
    <input type='checkbox' name='scatola' value=<%=rs_utenti("box")%> cecked>
    <%else%>
    <input type='checkbox' name='scatola' value=<%=rs_utenti("box")%>
    <%
    End if
    %>
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  9. #9
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    81
    non funziona

  10. #10
    codice:
    <%
    parametro = "no"
    valore = rs_utenti.Fields.Item("box").Value
    
    if isNumeric(valore) then valore = cLng(valore)
    
    if valore = 1 then 
    parametro = "yes"
    else
    parametro = "no"
    end if
    %>
    <input type="checkbox" name="scatola" value="<%=parametro%>" />

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.