doudang2537 2016-02-07 11:31
浏览 52
已采纳

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

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 11: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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?