2014-02-07 30 views
0

我需要從生活中的表單選擇選項變量,因爲它在相同形式的下一個字段中使用。任何線索如何做到這一點?我想這可以用JavaScript來完成,但我不知道如何使用JavaScript。提前致謝。 這裏是形式的代碼:PHP從表單選擇生活中獲取變量

echo ' <form action="dodaj_harmonogram.php" method="post">'; 

echo ' <div class="control-group"> 
    <label class="control-label">Nazwa harmonogramu:</label> 
    <div class="controls"> 
     <input type="text" name="nazwa_harmonogramu" required /> 
     <p class="help-block"></p> 
    </div> 
    </div>'; 
echo 'Profil:<br /> 
          <select name="profil"> 
           '; pobierz_profile(); 
           echo'</select><br>'; 
echo 'Playlista:<br /> 
<select name="playlista" id="lista"> 
'; pobierz_playlisty($id_playlisty); 
echo'</select><br>'; 
$czas_playlisty = zaokraglanieczasu(pobierz_czas_utworow_playlisty($id_playlisty)); 
$czas_sekundy = ceil($czas_playlisty); 
echo ' <div class="control-group"> 
    <label class="control-label">Odstęp (min):</label> 
    <div class="controls"> 
     <input type="number" min="'.$czas_sekundy.'" name="odstep" required /> 
     <p class="help-block"></p> 
    </div> 
    </div>'; 
echo ' <div class="control-group"> 
    <label class="control-label">Data od</label> 
    <div class="controls"> 
     <input type="date" name="data_od" required /> 
     <p class="help-block"></p> 
    </div> 
    </div>'; 
echo ' <div class="control-group"> 
    <label class="control-label">Data do</label> 
    <div class="controls"> 
     <input type="date" name="data_do" required /> 
     <p class="help-block"></p> 
    </div> 
    </div>'; 
echo ' Dni:<br />' ; 

?> 
<table class="table table-bordered" style="width: 20%;"> 
<thead><th>Nd</th><th>Pn</th><th>Wt</th><th>Śr</th><th>Cz</th><th>Pt</th><th>Sb</th> 
</thead> 
<tbody> 
<td><input type="checkbox" name="nd" value='1'></td> 
<td><input type="checkbox" name="pn" value='1'></td> 
<td><input type="checkbox" name="wt" value='1'></td> 
<td><input type="checkbox" name="sr" value='1'></td> 
<td><input type="checkbox" name="cz" value='1'></td> 
<td><input type="checkbox" name="pt" value='1'></td> 
<td><input type="checkbox" name="sb" value='1'></td> 
</tbody> 
</table> 
<br> 
<br> 
Godziny:<br /> 
<table class="table table-bordered"> 
<thead><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th> 
<th>12</th><th>13</th><th>14</th><th>15</th><th>16</th><th>17</th><th>18</th><th>19</th><th>20</th><th>21</th><th>22</th><th>23</th> 
</thead> 
<tbody>     
<td><input type="checkbox" name="0" value='1'></td> 
<td><input type="checkbox" name="1" value='1'></td> 
<td><input type="checkbox" name="2" value='1'></td> 
<td><input type="checkbox" name="3" value='1'></td> 
<td><input type="checkbox" name="4" value='1'></td> 
<td><input type="checkbox" name="5" value='1'></td> 
<td><input type="checkbox" name="6" value='1'></td> 
<td><input type="checkbox" name="7" value='1'></td> 
<td><input type="checkbox" name="8" value='1'></td> 
<td><input type="checkbox" name="9" value='1'></td> 
<td><input type="checkbox" name="10" value='1'></td> 
<td><input type="checkbox" name="11" value='1'></td> 
<td><input type="checkbox" name="12" value='1'></td> 
<td><input type="checkbox" name="13" value='1'></td> 
<td><input type="checkbox" name="14" value='1'></td> 
<td><input type="checkbox" name="15" value='1'></td> 
<td><input type="checkbox" name="16" value='1'></td> 
<td><input type="checkbox" name="17" value='1'></td> 
<td><input type="checkbox" name="18" value='1'></td> 
<td><input type="checkbox" name="19" value='1'></td> 
<td><input type="checkbox" name="20" value='1'></td> 
<td><input type="checkbox" name="21" value='1'></td> 
<td><input type="checkbox" name="22" value='1'></td> 
<td><input type="checkbox" name="23" value='1'></td> 
</tbody> 
</table>  
<br> 
<br> 

    <script>$(function(){ 
    $("input[type=checkbox]").on("click", function(){ 
     if($(this).is(':checked')) 
      $(this).parent().css('background-color', 'rgb(36, 255, 0)'); 
     else 
      $(this).parent().css('background-color', 'rgba(202, 202, 202, 0)'); 
    }); 
});</script> 


    <input type="submit" value="Dodaj "button" class="btn btn-info"></button> 
</form> 
+0

你是什麼意思的 '活' 呢?你的意思是什麼時候選擇的價值改變?編輯:你也需要把選擇框的值放在某個地方,或者只是把它存儲在一個變量中? – cbreezier

+0

我的意思是,當我從該選擇中選擇一個選項時,該選項的值將轉到一個變量,因爲它用於下一個字段 –

回答

0

包括jQuery的

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 

<script> 
// Then use an event handler to check when the select changes 
$('select').on('change', function() 
{ 
    // Show an alert 
    alert("The new value of the select is " + $(this).val()); 
    // You should place your logic here to do what you want with that value 
    // E.g. change the page 
    document.location.href = $(this).val(); 
}); 
</script> 
+0

我想將此選擇值獲取到變量例如$ example。我不需要任何警報。我需要這個變量從' –

+0

中選擇的'