Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Disabilitare un select se da un altro select si sceglie un certo valore

    Salve, sto scrivendo un form per gestire gli orari di apertura e chiusura di un negozio, inserendo orari a intervalli di mezz'ora in un select, dopo aver prelevato da un db l'orario di apertura/chiusura corrente.<br><br>Ovviamente se il negozio non apre, non ha un orario di chiusura, per cui sto cercando un modo per impostare il select dell'orario di chiusura su "Chiuso" e in modalità disabled quando il select dell'apertura è su "Chiuso".&nbsp;<img src="images/smilies/what.gif" border="0" alt="" title="Confused" smilieid="10" class="inlineimg"><br><br>Questo script non funziona bene...<br>
    codice:
    &lt;script&gt;<div>function change(value) {</div><div><span style="white-space:pre">    </span>if (value == "-off-") {</div><div><span style="white-space:pre">        </span>document.getElementById("chiusura1").innerHTML = "&lt;option selected disabled&gt;Chiuso&lt;/option&gt;";</div><div><span style="white-space:pre">    </span>} else {</div><div><span style="white-space:pre">        </span>document.getElementById("chiusura1").innerHTML = "&lt;option selected value='&lt;?php $chfema; ?&gt;'&gt;&lt;?php echo '$chfema'; ?&gt;&lt;/option&gt;&lt;option value='10:30'&gt;10:30&lt;/option&gt;&lt;option value='11:00'&gt;11:00&lt;/option&gt;&lt;option value='11:30'&gt;11:30&lt;/option&gt;&lt;option value='12:00'&gt;12:00&lt;/option&gt;&lt;option value='12:30'&gt;12:30&lt;/option&gt;&lt;option value='13:00'&gt;13:00&lt;/option&gt;&lt;option value='13:30'&gt;13:30&lt;/option&gt;&lt;option value='14:00'&gt;14:00&lt;/option&gt;";</div><div><span style="white-space:pre">    </span>}</div><div>}</div><div>change("-off-");</div>&lt;/script&gt;<br><br>&lt;select name="apfema" onchange="change(this.value)"&gt; ...<br><br><div>&lt;select id="chiusura1" name="chfema"&gt;<br><span style="white-space: pre;">    </span>&lt;option selected value="&lt;?php $chfema; ?&gt;"&gt;&lt;?php echo "$chfema"; ?&gt;&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="10:30"&gt;10:30&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="11:00"&gt;11:00&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="11:30"&gt;11:30&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="12:00"&gt;12:00&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="12:30"&gt;12:30&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="13:00"&gt;13:00&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="13:30"&gt;13:30&lt;/option&gt;</div><div><span style="white-space:pre">    </span>&lt;option value="14:00"&gt;14:00&lt;/option&gt;</div>&lt;/select&gt;
    <br>Al caricamento della pagina va bene, mette in selected gli orari caricati dal db, ed entrambi i menù sono attivi, ma se imposto Chiuso sull'orario di apertura, quello di chiusura va su Chiuso e ci resta anche se cambio l'orario di apertura.&nbsp;<img src="images/smilies/scalata.gif" border="0" alt="" title="Arrampicata libera" smilieid="46" class="inlineimg"><br>Vorrei inoltre non dover scrivere due volte l'elenco delle option (nella funzione e nel select): posso caricare la stringa in una variabile php?

  2. #2
    Cancellate questo post, per modificare l'originale me l'ha pubblicato due volte, e sballando la formattazione del codice.

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.