单选按钮值不能通过邮件发送

时间:2017-08-28 10:07:03

标签: php jquery html

仅采用第一个单选按钮

     <div class="field_radio" name="preference" >
       <input class="radio1" type="radio" name="preference" id="preference" 
         value="team"  onclick="ShowHideDiv()" /><label for="radio1">
         <span>Team</span></label>
      <input class="radio2" type="radio" name="preference" id="preference" 
         value="individual" onclick="ShowHideDiv()" /> <label for="radio2">
         <span>Individual</span></label>
     </div> 

Php部分

if (empty($_POST["preference"])) {
    $errorMSG .= "preference is required ";
} else {
    $preference = $_POST["preference"];
}

2 个答案:

答案 0 :(得分:3)

您在两个输入字段

上都使用相同的ID
<div class="field_radio" name="preference">
    <input class="radio1" type="radio" name="preference" id="preference_one"         value="team"  onclick="ShowHideDiv()" />
    <input class="radio2" type="radio" name="preference" id="preference_two" 
     value="individual" onclick="ShowHideDiv()" />
</div>

答案 1 :(得分:0)

<div class="field_radio">
    <input type="radio" class="radio1" name="preference" id="preference1" value="team" onclick="ShowHideDiv()" />
    <label for="radio1"><span>Team</span></label>
    <input type="radio" class="radio2" name="preference" id="preference2" value="individual" onclick="ShowHideDiv()" />
    <label for="radio2"><span>Individual</span></label>
</div>

注意:单选按钮是相同的,使它不同将解决您的问题!