我目前工作的一個形式。如果用戶沒有從清單中選擇任何選項,我想顯示警報。我看過很多與這個問題有關的帖子,但沒有什麼幫助。我沒有任何關於JavaScript編碼的想法。我的代碼如下:如果在PHP中沒有從複選框中選擇任何選項,如何在屏幕上顯示警報?
的index.php
<form name='form1' method="post" action="checkbox_value.php" >
<div class="dropdownstay">
<select name="city" class="option3" id="dropdown">
<option value="1" id="1" style="font-size:20px; font-family:Monotype Corsiva;">Lahore</option>
<option value="2" id="2" style="font-size:20px; font-family:Monotype Corsiva;">Dubai </option>
<option value="3" id="3" style="font-size:20px; font-family:Monotype Corsiva;">Newyork</option>
<option value="4" id="4" style="font-size:20px; font-family:Monotype Corsiva;">Canberra</option>
<option value="5" id="5" style="font-size:20px; font-family:Monotype Corsiva;">Kuala Lampur</option>
<br>
</select>
<!--end for drop down -->
</div>
</div>
</li>
</ul>
</div>
<div class="reservation">
<ul>
<li class="span1_of_1">
<h5>What you want in hotel?</h5>
<br>
<section title="preferences">
<input type="checkbox" value="is_pool" id="pool" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Pool </text>
<br/>
<input type="checkbox" value="is_gym" id="gym" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Gym </text>
<br/>
<input type="checkbox" value="is_beach" id="beach" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Beach </text>
<br/>
<input type="checkbox" value="is_spa" id="spa" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Spa </text>
<br/>
<input type="checkbox" value="is_wifi" id="wifi" name="check_list[]" checked />
<text style="font-size:20px; font-family: Times New Roman;"> Wifi </text>
<br/>
<input type="checkbox" value="is_familyoriented" id="family" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Family Friendly</text>
<br/>
<input type="checkbox" value="is_economical" id="economical" name="check_list[]" />
<text style="font-size:20px; font-family: Times New Roman;"> Economical </text>
<br>
<br>
<br>
<br>
</section>
<input type="submit" name="submit" value="Submit" />
</form>
</li>
試圖執行通過選擇標籤的JavaScript代碼,但然後取出它們,當我到現在選擇標籤的下拉列表。
的問題是,如果用戶不選擇從清單的任何選項,並重定向到checkbox_value.php頁面不顯示警報。我無法弄清楚如何實現複選框場景的驗證。只有在從列表中選中任何選項的情況下,我纔想將其重定向到該頁面。任何幫助完成這項任務應該是非常可觀的。
爲什麼你打開你的表單兩次? 你想只爲第一選擇或爲所有的表單驗證? 你爲什麼選擇包含內聯CSS? – Luca
對不起,一定是編輯錯誤。我沒有在我的代碼中打開過兩次。 – user399
忽略形式的開口 – user399