0

My problem is that I can not select radio buttons. I am using php mysql and create radio buttons in while loop for mysql_fetch_array function. Here is the code:

<div class="alert alert-info">
     <label id="dataFlow">
          <?php if($detailPage == TRUE && $detailType == "poll"){ ?>
              <!-- survey part -->                                
              <h3><?php echo $pollData['pollContent']; ?></h3>
                   <form id="pollForm" method="post" action="">
                        <p>
                             <?php while($pollAnswerData = $pollAnswerDataSql->fetch_assoc()) {
                                                echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" />' . $pollAnswerData['pollquestionContent'] . '<br/>'; 
                                            } ?>      
                                        </p>
                       <input type="submit" name="submitButton" id="submitButton" value="Gönder"/>
                       </form>
                 <?php } else if($detailPage == TRUE && $detailType == "post") { ?>
                  <h4><?php echo $postData['postContent']; ?></h4>
             <?php } else { 
                  listFlowData();
             } ?>
      </label>                            
 </div>

What is the problem in here?

4

4 回答 4

1

输入元素(单选或复选框)未选中但已选中。要在浏览器中显示处于选中状态的元素,您必须向元素添加布尔“选中”属性。

<input type="radio" checked="checked" id="..." name="..." value="..."/>

请注意,浏览器仅将选中元素的值发送到您的服务器端脚本。要识别未选中的元素,您必须使用内部列表。

对于单选输入,这意味着仅当用户单击其中一个元素(或使用属性检查)时,命名参数才会存在于表单请求中。

于 2013-11-11T09:18:59.007 回答
0

in Google chrome you may not be facing any problems. in Firefox, there is a problem. and the problem I figured out is that your form is within a label. remove the label tag and it should be all fine. even the non unique ID does not hurt in any browser(tested on chrome, Firefox and IE9)

below is the HTML I have been testing for you. uncomment the label and you will get the problem. hope it helps.

NOTE: The ID of each radio button is kept deliberately same to demonstrate that browser ignore this.

<html>
<head></head>
<body>
<!-- <label id="dataFlow"> -->
<form id="pollForm" method="post" action="">
<input type = "radio" id="rdo1" name = "poll_radio" value = "dsfsr"/>111<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsddf"/>222<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsfdf"/>333<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rshdf"/>444<br/>
<input type="submit" name="submitButton" id="submitButton" value="Gender"/>
</form>
<!-- </label> -->
</body>
</html>
于 2013-11-11T09:39:12.973 回答
0

好像你缺少值属性

http://www.w3schools.com/html/html_forms.asp

<input type="radio" name="sex" value="male">
于 2013-11-11T09:12:41.180 回答
0

您可以更改这行代码

echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" />' . $pollAnswerData['pollquestionContent'] . '<br/>';

对此。

echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" value="' . $pollAnswerData['pollquestionId'] . '"/>' . $pollAnswerData['pollquestionContent'] . '<br/>';

希望 $pollAnswerData['pollquestionId'] 是一个唯一值。未选中单选框,因为您没有在单选框中插入值。您应该插入值,该值必须在每次循环重复时更改。

谢谢。

于 2013-11-11T09:22:10.160 回答