Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在按钮单击事件后更改文本框、选择框和复选框值? 名称:_Php_Html_Url_Submit Button - Fatal编程技术网

Php 如何在按钮单击事件后更改文本框、选择框和复选框值? 名称:

Php 如何在按钮单击事件后更改文本框、选择框和复选框值? 名称:,php,html,url,submit-button,Php,Html,Url,Submit Button,将表单方法从POST更改为GET,这将在querystring中存储变量,并使您的$\u GET变量可以访问这些变量。有两种方法: 将方法更改为get: 将回显的值更改为: 对于选择: <html> <body> <form method="post"> Name :<input type = "text" name= "name" value = "<?php echo $_GET["name"];?>">

将表单方法从POST更改为GET,这将在querystring中存储变量,并使您的
$\u GET
变量可以访问这些变量。

有两种方法:

  • 将方法更改为
    get

  • 将回显的值更改为:

  • 对于选择:

    <html>
    <body>
        <form method="post">
         Name :<input type = "text" name= "name" value = "<?php echo $_GET["name"];?>">
         salary :<input type = "number" name = "salary" value = "<?php echo $_GET["salary"]?>">
         <input type = "submit" value = "submit">
        </form>
    </body>
    </html>
    
    
    
    它不起作用。顺便说一下,在单击submit按钮之前,name and salary按钮将显示从url获取的信息。然后,如果我们更改姓名和薪资值,然后单击“提交”按钮,则需要显示新记录。我该怎么做?如果我遇到复选框、选择框和单选按钮的相同情况,我该怎么办?您只需检查相应post或get中的值是否等于选项中的值,如果是,则添加stAttribute“selected”、“checked”等,如果不是,则忽略它。我想,但是您没有在代码中提供任何复选框或选项。
    <select name = "department">
        <?php $output = $connection->get_department(); 
        if($output["status"] == 1){ 
            $array = $output["array"]; 
            foreach($array as $res){?> 
                <option value = "<?php echo $res["id"];?>">
                <?php echo $res["name"]; 
               if(isset($_POST["name"]) && $_POST["name"] == $res["name"]){
                   echo " selected"; 
               }?>
                </option>
            <?php
            } 
        } 
        ?> 
    </select>