Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    111

    eliminare i nomi una volta scelti del tag select

    ciao a tutti non so se è possibile, però se lo fosse quello che ho in mente verrebbe una cosa carina per il sito che sto facendo.
    Vengo al dunque ho per ipotesi 8 campi select in un form, i dati li prendo da un db con una query (diciamo la prima select) poi con un onchange e uno script in ajax vorrei interrogare di nuovo il db per togliere quello scelto (ipotesi 8 nomi ne dovrei trovare 7 e man mano che scelgo uguale per gli altri fino arrivare a 1)... spero di essermi spiegato bene!
    è fattibile la cosa con il php visto che devo interrogare il db? se si qualcuno mi può postare un esempio?

    grazie ciao

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    3,709
    sì può fare, certo... parti con l'html semplice e crea gli eventi onclick chiamando una tua funzione che per ora puoi lasciare vuota o realizzare con codice fittizio (esempio: facendo togliere sempre la prima voce)... successivamente nella funzione richiamerai via ajax un tuo script php che riceve i dati, interroga il db e restituisce il valore giusto

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    111
    ciao ho risolto così senza usare ajax ma solo javascript... vi posto la mia idea:

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <?php
                                    
    include "config.php";   
                                    include 
    "connessione.php"
                                    
                                    
    $sql "SELECT squadra FROM squadre";
                                     
    $ris mysql_query($sql$db) or die('QUERY SQL FALLITA');
                                    
    $arrsquadra 1;
                                     while (
    $row = @mysql_fetch_array($ris)){
                                    
                                    
    $squdra[$arrsquadra] = $row['squadra'];
                                    
    $arrsquadra++;
                                    
                                     }
                                     
                                     
    ?>




    <script type="text/javascript">
    /* script prima scelta */
    function prima_scelta(){
    var sq1 = "<?php echo "$squdra[1]"?>";
    var sq2 = "<?php echo "$squdra[2]"?>";
    var sq3 = "<?php echo "$squdra[3]"?>";
    var sq4 = "<?php echo "$squdra[4]"?>";

    if (prova.squadra1.value == sq1)
    {
     document.getElementById("op5").style.display = 'none';
       document.getElementById("op9").style.display = 'none';
        document.getElementById("op13").style.display = 'none';
      
    }
    if (prova.squadra1.value == sq2)
    {
    document.getElementById("op6").style.display = 'none';
     document.getElementById("op10").style.display = 'none';
      document.getElementById("op14").style.display = 'none';

    }
    if (prova.squadra1.value == sq3)
    {
    document.getElementById("op7").style.display = 'none';
     document.getElementById("op11").style.display = 'none';
      document.getElementById("op15").style.display = 'none';
    }
    if (prova.squadra1.value == sq4)
    {
    document.getElementById("op8").style.display = 'none';
          document.getElementById("op12").style.display = 'none';
          document.getElementById("op16").style.display = 'none';
     
    }
    }
    </script>
    <script type="text/javascript">
    /* script seconda scelta */
    function seconda_scelta(){
    var sq1 = "<?php echo "$squdra[1]"?>";
    var sq2 = "<?php echo "$squdra[2]"?>";
    var sq3 = "<?php echo "$squdra[3]"?>";
    var sq4 = "<?php echo "$squdra[4]"?>";


    if (prova.squadra2.value == sq1)
    {
     document.getElementById("op9").style.display = 'none';
      document.getElementById("op13").style.display = 'none';
       document.getElementById("op1").style.display = 'none';
      
    }
    if (prova.squadra2.value == sq2)
    {
    document.getElementById("op10").style.display = 'none';
     document.getElementById("op14").style.display = 'none';
      document.getElementById("op2").style.display = 'none';
    }
    if (prova.squadra2.value == sq3)
    {
    document.getElementById("op11").style.display = 'none';
     document.getElementById("op15").style.display = 'none';
      document.getElementById("op3").style.display = 'none';
     
    }
    if (prova.squadra2.value == sq4)
    {
    document.getElementById("op12").style.display = 'none';
     document.getElementById("op16").style.display = 'none';
      document.getElementById("op4").style.display = 'none';
     
    }
    }
    </script>
    <script type="text/javascript">
    /* script seconda scelta */
    function terza_scelta(){
    var sq1 = "<?php echo "$squdra[1]"?>";
    var sq2 = "<?php echo "$squdra[2]"?>";
    var sq3 = "<?php echo "$squdra[3]"?>";
    var sq4 = "<?php echo "$squdra[4]"?>";


    if (prova.squadra3.value == sq1)
    {
     document.getElementById("op13").style.display = 'none';
      document.getElementById("op5").style.display = 'none';
       document.getElementById("op1").style.display = 'none';
      
    }
    if (prova.squadra3.value == sq2)
    {
    document.getElementById("op14").style.display = 'none';
     document.getElementById("op6").style.display = 'none';
      document.getElementById("op2").style.display = 'none';
    }
    if (prova.squadra3.value == sq3)
    {
    document.getElementById("op15").style.display = 'none';
      document.getElementById("op7").style.display = 'none';
       document.getElementById("op3").style.display = 'none';
    }
    if (prova.squadra3.value == sq4)
    {
    document.getElementById("op16").style.display = 'none';
      document.getElementById("op8").style.display = 'none';
       document.getElementById("op4").style.display = 'none';
    }
    }
    </script>
    <script type="text/javascript">
    /* script seconda scelta */
    function quarta_scelta(){
    var sq1 = "<?php echo "$squdra[1]"?>";
    var sq2 = "<?php echo "$squdra[2]"?>";
    var sq3 = "<?php echo "$squdra[3]"?>";
    var sq4 = "<?php echo "$squdra[4]"?>";


    if (prova.squadra4.value == sq1)
    {
     document.getElementById("op1").style.display = 'none';
      document.getElementById("op5").style.display = 'none';
       document.getElementById("op9").style.display = 'none';
      
    }
    if (prova.squadra4.value == sq2)
    {
    document.getElementById("op2").style.display = 'none';
     document.getElementById("op6").style.display = 'none';
      document.getElementById("op10").style.display = 'none';
    }
    if (prova.squadra4.value == sq3)
    {
    document.getElementById("op11").style.display = 'none';
      document.getElementById("op7").style.display = 'none';
       document.getElementById("op3").style.display = 'none';
    }
    if (prova.squadra4.value == sq4)
    {
    document.getElementById("op12").style.display = 'none';
      document.getElementById("op8").style.display = 'none';
       document.getElementById("op4").style.display = 'none';
    }
    }
    </script>
    </head>

    <body>

    <form name="prova" id="prova" action="" method="post">

    <?php
                                    
    include "config.php";   
                                    include 
    "connessione.php"
                                    
                                    
    $sql "SELECT squadra FROM squadre";
                                     
    $ris mysql_query($sql$db) or die('QUERY SQL FALLITA');
                                    
    $conta_sq1 1;
                                    echo 
    "<select name='squadra1' onchange='prima_scelta(this.value)'>";
                                    echo 
    "<option value=''></option>";
                                      while (
    $row = @mysql_fetch_array($ris)){
                                    
                                    
    $squdra $row['squadra'];

    echo 
    "<option id='op$conta_sq1' value='$squdra'>$squdra</option>";

    $conta_sq1++;
                                      }

    ?>
    </select>

    <?php
                                    
    include "config.php";   
                                    include 
    "connessione.php"
                                    
                                    
    $sql "SELECT squadra FROM squadre";
                                     
    $ris mysql_query($sql$db) or die('QUERY SQL FALLITA');
                                    
    $conta_sq2 5;
                                    echo 
    "<select name='squadra2' onchange='seconda_scelta(this.value)'>";
                                    echo 
    "<option value=''></option>";
                                      while (
    $row = @mysql_fetch_array($ris)){
                                    
                                    
    $squdra $row['squadra'];

    echo 
    "<option id='op$conta_sq2' value='$squdra'>$squdra</option>";

    $conta_sq2++;
                                      }

    ?>

    </select>

    <?php
                                    
    include "config.php";   
                                    include 
    "connessione.php"
                                    
                                    
    $sql "SELECT squadra FROM squadre";
                                     
    $ris mysql_query($sql$db) or die('QUERY SQL FALLITA');
                                    
    $conta_sq3 9;
                                    echo 
    "<select name='squadra3' onchange='terza_scelta(this.value)'>";
                                    echo 
    "<option value=''></option>";
                                      while (
    $row = @mysql_fetch_array($ris)){
                                    
                                    
    $squdra $row['squadra'];

    echo 
    "<option id='op$conta_sq3' value='$squdra'>$squdra</option>";

    $conta_sq3++;
                                      }

    ?>

    </select>

    <?php
                                    
    include "config.php";   
                                    include 
    "connessione.php"
                                    
                                    
    $sql "SELECT squadra FROM squadre";
                                     
    $ris mysql_query($sql$db) or die('QUERY SQL FALLITA');
                                    
    $conta_sq4 13;
                                    echo 
    "<select name='squadra4' onchange='quarta_scelta(this.value)'>";
                                    echo 
    "<option value=''></option>";
                                      while (
    $row = @mysql_fetch_array($ris)){
                                    
                                    
    $squdra $row['squadra'];

    echo 
    "<option id='op$conta_sq4' value='$squdra'>$squdra</option>";

    $conta_sq4++;
                                      }

    ?>

    </select>



    </form>




    </body>
    </html>

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    3,709
    ok... non ho seguito il tuo codice, però non può fare esattamente quello che dicevi originariamente, nel senso che se il db dev'essere interrogato in base ad una scelta devi per forza fare un refresh o una chiamata ajax... o forse avevo inteso male

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    111
    guarda che però lo fa nel senso adesso l'ho fatto semplificato dopo devo ampliarlo perchè avro 12 nomi invece che 4 e più caselle 12 totali se ci sono tutti i nomi;

    se nel primo caso ho questi nomi
    1) ciao
    2) pinco
    3) palla
    4) mondo
    se scelgo mondo lo script mi toglie quella voce su tutte le altre caselle con la funzione javascript
    codice:
    document.getElementById("op6").style.display = 'none';
    op(ed il numero) è id del tag option che mi nasconde la voce senza lasciare traccia, avevo provato con visibility ma restava un vuoto bianco!!!

    con ajax avevo provato dalla mia idea di partenza ma non mi veniva come volevo io, e così mi è venuto in mente questa idea... che avevo già usato per un altra pagina

    praticamente ricevo i nomi dal db e man mano che scelgo lo script me li "nasconde" per evitare di scegliere nomi doppi... magari non sarà evoluto ma fa quello che volevo io

    ciao

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    3,709
    avevo capito che però dovevi REINTERROGARE il db dopo la selezione... cmq l'importante è che funzioni! Ciao!!

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    111
    si era la mia idea iniziale che dopo aver scelto interrogava il db per eliminava il nome scelto, così facendo invece faccio delle query uniche nascondendo il nome scelto, e visto il risultato mi va bene anche così

    ciao

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.