Visualizzazione dei risultati da 1 a 9 su 9

Discussione: value checkbox

  1. #1
    Utente di HTML.it L'avatar di Mike
    Registrato dal
    May 2002
    Messaggi
    423

    value checkbox

    Salve,
    devo poter inserire in base dati il valore della proprieta value del mio checkbox:

    Codice PHP:
    <input type="checkbox" name="edtSR_PROD_CES" <?if($BC->GetFieldValue("SR_PROD_CES")=="true") { echo checked;}?> onchange="this.value=this.checked" />
    il problema e' che la proprieta value del mio checkbox non sempre assume valori corretti quando premo il pulsante "submit" .

    In sostanza vorrei che value assume la stessa identita' di checked (true o false) prima che premo il pulsante submit!

    PS: Ho provato al posto di onchange anche onclick e onsubmit......
    Mike

  2. #2
    <input type="checkbox" name="edtSR_PROD_CES" <? echo($BC->GetFieldValue("SR_PROD_CES")=="true")?'checked':' '?> onclick="funzione(this)" />


    funzione(oggetto)
    {
    if(oggetto.checked==true)
    {
    oggetto.value='valore'
    }
    else
    {
    oggetto.value='valore2'

    }
    }

  3. #3
    Utente di HTML.it L'avatar di Mike
    Registrato dal
    May 2002
    Messaggi
    423
    il problema e' che se il check non e' checked su submit la variabile php e' vuota

    Codice PHP:
    <form id="form1" name="form1" method="post" action="provacheck.php">
    <script language="javascript">

    function funcheck(oggetto){
        if(oggetto.checked==true)
        {
            oggetto.value='true'
            //alert(oggetto.value)
        }else{
            
            oggetto.value='false'
            //alert(oggetto.value)
        }
    //return(oggetto.value);
    }
    </script>

      



        <input name="ch" type="checkbox" id="ch" value="true" onClick="funcheck(this)" >

    </p>

      



        <input name="ch2" type="checkbox" id="ch2" value="true" onClick="funcheck(this)" >

    </p>

      



        <input type="submit" name="button" id="button" value="Submit"/>

    </p>

    </form>

    //////////////////// file php////////////////////////////

    <?
    echo $_POST['ch'];
    echo 
    "
    "
    .$_POST['ch2'];


    ?>
    Mike

  4. #4
    Setti un campo hidden e dici che se il check non è checkato,prendi il campo hidden.. no??
    Così non serve che fai la funzione ma metti sul value del checkbox 'true' sull'hidden false

    No??

  5. #5
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Non ho capito cosa ci fa questo thread sul forum php, comunque è una regola di base dell'html che i browser non inviano le checkbox non selezionate.

  6. #6
    Utente di HTML.it L'avatar di Mike
    Registrato dal
    May 2002
    Messaggi
    423
    Intanto scusa se ho sbagliato thread, e' stata una mia distrazione....

    Come faccio a fare quello che dici?

    • Setti un campo hidden e dici che se il check non è checkato,prendi il campo hidden.. no??
      Così non serve che fai la funzione ma metti sul value del checkbox 'true' sull'hidden false

      No??
    Mike

  7. #7
    <input type="checkbox" id='check' value='true'>
    <input type='hidden' id='chack2' value='false'>

    via php fai

    If(isset($_POST['check']))
    $variabile=$_POST['check'];
    else
    $variabile=$_POST['check2'];

  8. #8
    Utente di HTML.it L'avatar di Mike
    Registrato dal
    May 2002
    Messaggi
    423


    purtroppo devo gestire il tutto dentro il form prima che invio le var a php!!

    Mike

  9. #9
    Allora fai un input hidden e prendi quel valore SEMPRE anziche prendere il value del checkbox...
    sull onclick del checkbox fai una funzione così..

    function funcheck(oggetto){
    if(oggetto.checked==true)
    {
    document.getElementById("idcampohidden").value='tr ue'
    //alert(oggetto.value)
    }else{

    document.getElementById("idcampohidden").value='fa lse'
    //alert(oggetto.value)
    }

    capito?

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.