如何从PHP获取选定的单选按钮值onclick

Mithun Ds

我想在php中获取选定的单选按钮的值。

代码:update.php

<html>
    <head>
        <link rel="stylesheet" href="css/common.css" type="text/css">
        <link rel="stylesheet" type="text/css" href="css/page.css">
        <link href="css/loginmodule.css" rel="stylesheet" type="text/css" />

        <script>
            function showUser(str) {
                if (str == "") {
                    document.getElementById("txtHint").innerHTML = "";
                    return;
                }

                if (window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                } else {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET", "gettheater.php?q=" + str, true);
                xmlhttp.send();
            }



        </script>       





    </head>
    <body>

        <h1>Welcome <?php echo $_SESSION['SESS_FIRST_NAME']; ?></h1>
        <a href="member-profile.php" class="log">My Profile</a> | <a href="logout.php" class="log">Logout</a>
        <p>This is a password protected area only accessible to Admins. </p>

    <center>
        <div class="pan"><br><br>
            <div class="head">Remove Theater From List</div>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >


                <table>
                    <tr>
                        <td>
                            <table>
                                <tr>
                                    <td><label for="Theatername">Theater Name</label></td>
                                    <td>
                                        <?php
                                        try {
                                            $dbh = new PDO('mysql:dbname=theaterdb;host=localhost', 'tiger', 'tiger');
                                        } catch (PDOException $e) {
                                            echo 'Connection failed: ' . $e->getMessage();
                                        }

                                        $sql = "SELECT theater_name FROM theater;";

                                        $sth = $dbh->prepare($sql);
                                        $sth->execute();

                                        echo "<select name='theater_name' id='course' onchange='showUser(this.value);'>";
                                        echo "<option>----Select Theater----</option>";
                                        while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
                                            echo "<option value='" . $row['theater_name'] . "'>" . $row['theater_name'] . "</option>";
                                        }
                                        echo "</select>";
                                        ?>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr> 
            </form>


            <tr>
                <td>
                    <form method="POST">
                        <table>
                            <tr>
                                <td><label for="Address">Address</label></td>
                                <td><div id="txtHint">
                                    </div></td>
                            </tr>


                            <tr>
                                <td></td>
                                <td><input type="submit" name='Remove From List' value="Remove From List" class="getvalue" onclick="< ? php myfunc() ? >"/></td>
                            </tr>
                        </table>

                        </table> 
                    </form>
                    <br><br>
            </tr>
            </td>
            <?php
            if (isset($_POST['Submit'])) {
                echo $_POST['address'];
            }
            ?>
        </div>
    </center>
</body>
</html>

代码
gettheater.php

<?php
$q = strtolower(trim($_GET["q"]));

try {
    $dbh = new PDO('mysql:dbname=theaterdb;host=localhost', 'tiger', 'tiger');
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

$sql = 'SELECT address FROM theater WHERE LOWER(theater_name) = :q';

$sth = $dbh->prepare($sql);
$sth->bindValue(':q', $q);
$sth->execute();

echo "<form name='theater' method='POST' action='update.php'>";
echo "<table border='0' class='tabs'><tr><th>Theater Address</th><th>Select</th></tr>";

while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
    echo "<tr>";
    echo "<td class='ad'>" . $row['address'] . "</td>";
    echo "<td>";
    echo '<input type="radio" name="address" value="43"  />';
    echo "</td>";
    echo "</tr>";
}

echo "</table>";
echo "</form>";
$dbh = null;
?>

单选按钮的html位于gettheater.php页面中。但是我正在运行update.phpgettheater页面,update.php但是如何获取选定的单选按钮值,我想在中获取选定的单选按钮值update.php

我怎样才能做到这一点?

萨姆

检查表单是否已提交,然后用于$_POST[]访问数据。

参见http://php.net/manual/en/reserved.variables.post.php

您可能要包括一个提交按钮,这将使您可以检查表单是否首先提交。

echo "<form name='theater' method='POST' action='update.php'>";
echo '<input type="submit" value="Enter" name="submit">';

去检查

if (isset($_POST['submit'])) {
    //Do something
}

如果不这样做,则通常可以使用隐藏字段。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何获取选定的单选按钮值?

来自分类Dev

如何在Mvc中获取选定的单选按钮值

来自分类Dev

如何从expressjs获取表单内的选定单选按钮值?

来自分类Dev

如何从获取数组结果中检索单选按钮的选定值..?

来自分类Dev

我如何获取 angularjs 中选定单选按钮的值?

来自分类Dev

JavaScript - 如何获取动态单选按钮名称和选定值?

来自分类Dev

如何获取PHP中单选按钮的值?

来自分类Dev

在JavaScript中获取选定的单选按钮值

来自分类Dev

在JavaScript中获取选定的单选按钮值

来自分类Dev

获取单选按钮列表的选定值

来自分类Dev

如何从意图中获取选定的单选按钮?

来自分类Dev

从片段中的单选组中获取选定的单选按钮值

来自分类Dev

获取单选按钮值php

来自分类Dev

如何获取单选按钮的值?

来自分类Dev

如何获取表中单选按钮的值-PHP

来自分类Dev

如何从php中的单选按钮获取多个值

来自分类Dev

如何使用Angular中的For循环从Mat-radio-group中获取选定的单选按钮值

来自分类Dev

如何在另一个jsp页面上获取选定的单选按钮值?

来自分类Dev

如何使用jQuery中的类获取选定单选按钮和复选框的值?

来自分类Dev

如何从angular Js的html中的单选按钮中获取选定的值

来自分类Dev

如何从单选按钮列表和复选框列表中获取选定的值?

来自分类Dev

Bootstrap单选按钮:在提交表单上获取选定的值

来自分类Dev

获取当前选定单选按钮的隐藏值

来自分类Dev

使用jQuery获取选中的单选按钮和“选定”下拉值

来自分类Dev

使用jQuery从选定的单选按钮获取文本值

来自分类Dev

获取当前选定单选按钮的隐藏值

来自分类Dev

在 Ajax 生成的工具提示中获取选定的单选按钮值

来自分类Dev

如何根据选定的值传递单选按钮值?

来自分类Dev

如何仅基于选定的单选按钮获取总和?

Related 相关文章

  1. 1

    如何获取选定的单选按钮值?

  2. 2

    如何在Mvc中获取选定的单选按钮值

  3. 3

    如何从expressjs获取表单内的选定单选按钮值?

  4. 4

    如何从获取数组结果中检索单选按钮的选定值..?

  5. 5

    我如何获取 angularjs 中选定单选按钮的值?

  6. 6

    JavaScript - 如何获取动态单选按钮名称和选定值?

  7. 7

    如何获取PHP中单选按钮的值?

  8. 8

    在JavaScript中获取选定的单选按钮值

  9. 9

    在JavaScript中获取选定的单选按钮值

  10. 10

    获取单选按钮列表的选定值

  11. 11

    如何从意图中获取选定的单选按钮?

  12. 12

    从片段中的单选组中获取选定的单选按钮值

  13. 13

    获取单选按钮值php

  14. 14

    如何获取单选按钮的值?

  15. 15

    如何获取表中单选按钮的值-PHP

  16. 16

    如何从php中的单选按钮获取多个值

  17. 17

    如何使用Angular中的For循环从Mat-radio-group中获取选定的单选按钮值

  18. 18

    如何在另一个jsp页面上获取选定的单选按钮值?

  19. 19

    如何使用jQuery中的类获取选定单选按钮和复选框的值?

  20. 20

    如何从angular Js的html中的单选按钮中获取选定的值

  21. 21

    如何从单选按钮列表和复选框列表中获取选定的值?

  22. 22

    Bootstrap单选按钮:在提交表单上获取选定的值

  23. 23

    获取当前选定单选按钮的隐藏值

  24. 24

    使用jQuery获取选中的单选按钮和“选定”下拉值

  25. 25

    使用jQuery从选定的单选按钮获取文本值

  26. 26

    获取当前选定单选按钮的隐藏值

  27. 27

    在 Ajax 生成的工具提示中获取选定的单选按钮值

  28. 28

    如何根据选定的值传递单选按钮值?

  29. 29

    如何仅基于选定的单选按钮获取总和?

热门标签

归档