doudang2537
2016-02-07 19:31
浏览 51
已采纳

如何根据单选按钮选择更改表单提交页面上的文本? [重复]

This question already has an answer here:

On "form.html", I have a basic HTML form:

<form method="post" action="submit.php">
  <input type="radio" name="SQ1" value="y"> Yes<br>
  <input type="radio" name="SQ1" value="n"> No<br>
  <input type="submit">
</form>

On "submit.php", I have a table. I am trying to change the text inside the table based on what radio button is selected.

<table id="results">
    <tr>
        <th>h1</th>
        <th>h2</th>
        <th>h3</th>
        <th>h4</th>
        <th>h5</th>
        <th>h6</th>
    </tr>
    <tr>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "0";
            }
            else {
                echo "1";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "0";
            }
            else {
                echo "1";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
                <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
                <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
    </tr>
</table>

No matter what button is selected, the data appears as if $sq1 = y.

</div>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmeirang4679 2016-02-07 19:38
    已采纳

    You have problem with your if statement condition, 1) if($sq1=y) will return true it is assignment operation

    2) y is string use the double quotation "y".

    3) to compare string use == or strcmp($var1,$var2) which returns 0 in case of equal strings

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题