2017-09-14 65 views
1

我今天完成了我的標記工作,並開始研究代碼。所以我們在這裏是我的標記代碼。複選框兩個複選框正在檢查

<form action="" id='createchar'> 
     <div id="wrapper"> 

      <!-- Main --> 
       <section id="main"> 
        <header> 
         <h1>Create New Character</h1> 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="username" placeholder="პერსონაჟის სახელი"/> 
         <input type="checkbox" value="1" id="checkboxFourInput" name="male"/> 
         <label for="checkboxFourInput" style="margin-left: 9px;">კაცი</label> 
         <input type="checkbox" value="2" id="checkboxFourInput2" name="female"/> 
         <label for="checkboxFourInput2" style="margin-right: 810px;margin-top: 15px;">ქალი</label> 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="explainmg" placeholder="განმარტეთ METAGAMING-ი"/> 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="explainpg" placeholder="განმარტეთ POWERGAMING-ი"/> 
         <textarea rows="10" cols="10" name="charbio" placeholder="დაწერეთ თქვენი პერსონაჟის ბიოგრაფი" style="margin-top: 10px; width: 1000px;"></textarea> 
        </header> 
       </section> 

      <!-- Footer --> 
       <footer id="footer"> 
        <ul class="copyright"> 
         <li>&copy; <a href="http://ls-rp.ge">LS-RP.GE</a></li><li>Design</li> 
        </ul> 
       </footer> 

     </div> 
    </form> 

我有這個問題。兩個複選框正在檢查,但我想避免它。我怎麼做到的?

+2

應該使用無線電代替。確保將它們添加到同一組 – Jaya

回答

5

基本上你應該使用一個radio

<form action="" id='createchar'> 
 
     <div id="wrapper"> 
 

 
      <!-- Main --> 
 
       <section id="main"> 
 
        <header> 
 
         <h1>Create New Character</h1> 
 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="username" placeholder="პერსონაჟის სახელი"/> 
 
         <input type="radio" value="1" id="checkboxFourInput" name="gender" value="male" /> 
 
         <label for="checkboxFourInput" style="margin-left: 9px;">კაცი</label> 
 
         <input type="radio" value="2" id="checkboxFourInput2" name="gender" value="female"/> 
 
         <label for="checkboxFourInput2" style="margin-right: 810px;margin-top: 15px;">ქალი</label> 
 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="explainmg" placeholder="განმარტეთ METAGAMING-ი"/> 
 
         <input type="text" style="margin-top: 10px; width: 1000px;" name="explainpg" placeholder="განმარტეთ POWERGAMING-ი"/> 
 
         <textarea rows="10" cols="10" name="charbio" placeholder="დაწერეთ თქვენი პერსონაჟის ბიოგრაფი" style="margin-top: 10px; width: 1000px;"></textarea> 
 
        </header> 
 
       </section> 
 

 
      <!-- Footer --> 
 
       <footer id="footer"> 
 
        <ul class="copyright"> 
 
         <li>&copy; <a href="http://ls-rp.ge">LS-RP.GE</a></li><li>Design</li> 
 
        </ul> 
 
       </footer> 
 

 
     </div> 
 
    </form>

注意,當使用radio你應該有所有相關的元素在name屬性相同 值。

+0

謝謝檢查這兩個複選框是固定的。但我還有一個問題,我想檢測性別的價值,'if($ _ POST ['gender'] =='male)...'這會工作嗎? –

+1

是的,這正是它的工作原理。 – Dekel