Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Disabilitazione select

  1. #1
    Utente di HTML.it L'avatar di fraude
    Registrato dal
    Feb 2004
    Messaggi
    2,870

    Disabilitazione select

    Ciao.

    Ho questa pagina web nella quale le select CO e ZN si disabilitano a vicenda quando in una delle due viene selezionato una valore diverso da -1.

    Come modifico la funzione javascript Attiva anche per evitare che nella terza select AUT non sia possibile selezionare il valore 2 quando si è selezionato il valore diverso da -1 nella select CO ?

    codice:
    function Attiva()
    
    { 
    
        var sel = document.getElementById('CO'); 
        var sel1 = document.getElementById('ZN'); 
        
        if (sel.options[sel.selectedIndex].value != '-1') { 
            document.getElementById('ZN').disabled = true; 
        } 
    
        else { 
            document.getElementById('ZN').disabled = false; 
        }     
    
        if (sel1.options[sel1.selectedIndex].value != '-1') { 
            document.getElementById('CO').disabled = true; 
            document.getElementById('AUT').value = 2; 
            document.getElementById('AUT').disabled = true; 
        }     
    
        else { 
            document.getElementById('CO').disabled = false; 
        }    
    }
    
    <select size="1" name="CO" id="CO" onchange="Attiva();">
    <option value="-1" selected="selected">- Seleziona -</option>
    ...
    </select>
    
    <select size="1" name="CO" id="ZN" onchange="Attiva();"> 
    <option value="-1" selected="selected">- Seleziona -</option> 
    ...
    </select> 
    
    <select size="1" name="AUT" id="AUT">
    <option>Seleziona</option>
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    Grazie---

  2. #2
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Prova questo... ciao!

    Codice PHP:
    <html>
    <
    head>
    <
    script language="javascript">
    function 
    Attiva()

        var 
    sel document.getElementById('CO'); 
        var 
    sel1 document.getElementById('ZN'); 
        
        if (
    sel.options[sel.selectedIndex].value != '-1')
        { 
            
    document.getElementById("opzione2").disabled=true;
            
    document.getElementById('ZN').disabled true
        } 
        else
        { 
            
    document.getElementById("opzione2").disabled=false;
            
    document.getElementById('ZN').disabled false
        }     

        if (
    sel1.options[sel1.selectedIndex].value != '-1')
        { 
            
    document.getElementById('CO').disabled true
            
    document.getElementById('AUT').value 2
            
    document.getElementById('AUT').disabled true
        }     
        else
        { 
            
    document.getElementById('CO').disabled false
            
    document.getElementById('AUT').disabled false
        }    
    }
    </script>
    </head>
    <body>



    <select size="1" name="CO" id="CO" onchange="Attiva();">
    <option value="-1" selected="selected">- Seleziona -</option>
    <option value="1">- 1 -</option>
    <option value="2">- 2 -</option>
    <option value="3">- 3 -</option>
    </select>

    <select size="1" name="CO" id="ZN" onchange="Attiva();"> 
    <option value="-1" selected="selected">- Seleziona -</option> 
    <option value="1">- 1 -</option>
    <option value="2">- 2 -</option>
    <option value="3">- 3 -</option>
    </select> 

    <select size="1" name="AUT" id="AUT">
    <option selected="selected">Seleziona</option>
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2" id="opzione2">2</option>
    <option value="3">3</option>
    </select>

    </body>
    </html> 
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

  3. #3
    Utente di HTML.it L'avatar di fraude
    Registrato dal
    Feb 2004
    Messaggi
    2,870
    Grazie ma non funziona. :master:

  4. #4
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Hai ragione... funziona sotto firefox, ma non sotto Explorer.. alle solite... scusa..
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

  5. #5
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Codice PHP:
    <html>
    <
    head>
    <
    script language="javascript">
    function 
    Attiva()

        var 
    sel document.getElementById('CO'); 
        var 
    sel1 document.getElementById('ZN'); 
        
        if (
    sel.options[sel.selectedIndex].value != '-1')
        { 
            
    document.getElementById("opzione2").disabled=true;
            
    document.getElementById('ZN').disabled true
        } 
        else
        { 
            
    document.getElementById("opzione2").disabled=false;
            
    document.getElementById('ZN').disabled false
        }     

        if (
    sel1.options[sel1.selectedIndex].value != '-1')
        { 
            
    document.getElementById('CO').disabled true
            
    document.getElementById('AUT').value 2
            
    document.getElementById('AUT').disabled true
        }     
        else
        { 
            
    document.getElementById('CO').disabled false
            
    document.getElementById('AUT').disabled false
        }    
    }
    function 
    check ()
    {
        var 
    sel document.getElementById('CO'); 

        if (
    sel.options[sel.selectedIndex].value != '-1')
        { 
            if (
    document.getElementById('AUT').value == 2)
            {
                
    alert ("non puoi selezionare questa opzione!");
                
    document.getElementById('AUT').value=-1;
            }    
            
        }
    }
    </script>
    </head>
    <body>



    <select size="1" name="CO" id="CO" onchange="Attiva();">
    <option value="-1" selected="selected">- Seleziona -</option>
    <option value="1">- 1 -</option>
    <option value="2">- 2 -</option>
    <option value="3">- 3 -</option>
    </select>

    <select size="1" name="CO" id="ZN" onchange="Attiva();"> 
    <option value="-1" selected="selected">- Seleziona -</option> 
    <option value="1">- 1 -</option>
    <option value="2">- 2 -</option>
    <option value="3">- 3 -</option>
    </select> 

    <select size="1" name="AUT" id="AUT" onchange="check();">
    <option value="-1" selected="selected">Seleziona</option>
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2" id="opzione2">2</option>
    <option value="3">3</option>
    </select>

    </body>
    </html> 
    Questa invece dovrebbe andare anche sotto explorer.. non è il massimo...
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

  6. #6
    Utente di HTML.it L'avatar di fraude
    Registrato dal
    Feb 2004
    Messaggi
    2,870
    Grazie !

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.